help small error

Started on the old forum in April 2012 · view the original in the archive · old links redirect here

3 replies · 342 views · started 14 years ago · 1 min read

3 participants
ozziemale31 Lead · 861 posts #1

if ($headmod != "friends/$user_id") { $frends = mysql_query("SELECT * FROM friends WHERE user_id = '$user_id' AND option"); $frends = mysql_fetch_array($frends); $new_frends = mysql_result(mysql_query("SELECT COUNT(*) FROM friends WHERE user_id = '$user_id' AND optionIN(1, 2)"), 0); if ($new_frends) $list[] = '<a href="' . $set['homeurl'] . '/users/friends.php?act=new' . ($frends['option'] == '2' ? '&amp;mod=delete' : '') . '">add</a> (+ ' . $new_frends . ')'; }

on profile i have

$friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `friends`='1' AND (`friend_id`='" . $user['id'] . "' AND `user_id`='$user_id') OR (`friend_id`='$user_id' AND `user_id`='" . $user['id'] . "')"), 0);
	if ($friends){
	echo '<a href="friends.php?act=add&user=' . $user['id'] . '">Add Friend</a>';
	}
	else {
	echo '<a href="friends.php?act=del&user=' . $user['id'] . '">Delete Friend</a>';
	}

now ive tried 1 2 and 3 in the value where it is selected on the dbase but on profiles it says delete instead of add any input will be appreciated as making something new

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

something else Fellow · 2,296 posts #2

I would advise on using mysql_num_rows() instead of mysql_result() because if it returns no rows then it will cause a silent error (you will see it when php error messages are turned on)

Added after 3 minutes:

also you might have to rearrange your ANDs/ORs to something like this:

"SELECT COUNT(*) FROM `friends` WHERE (`friends`='1' AND `friend_id`='" . $user['id'] . "' AND `user_id`='$user_id') OR (`friends`='1' AND `friend_id`='$user_id' AND `user_id`='" . $user['id'] . "')"

////blah some text here to fix bug with opera and this forum :/

(moving the friends='1' AND to include in both of the OR statements)

arnage Lead · 811 posts #3

hmmm, try this bro.

if ($headmod != "friends/$user_id") {
 $frends = mysql_query("SELECT * FROM `friends` WHERE `user_id` = '$user_id' AND `option`");
 while ($frends = mysql_fetch_array($frends)) {
 $new_frends = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user_id` = '$user_id' AND `option`IN(1, 2)"), 0);
 if ($new_frends) $list[] = '<a href="' . $set['homeurl'] . '/users/friends.php?act=new' . ($frends['option'] == '2' ? '&mod=delete' : '') . '">add</a> (+ ' . $new_frends . ')';
 }
}
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
ozziemale31 Lead · 861 posts #4

arnage wrote: hmmm, try this bro.

if ($headmod != "friends/$user_id") {
 $frends = mysql_query("SELECT * FROM `friends` WHERE `user_id` = '$user_id' AND `option`");
 while ($frends = mysql_fetch_array($frends)) {
 $new_frends = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user_id` = '$user_id' AND `option`IN(1, 2)"), 0);
 if ($new_frends) $list[] = '<a href="' . $set['homeurl'] . '/users/friends.php?act=new' . ($frends['option'] == '2' ? '&mod=delete' : '') . '">add</a> (+ ' . $new_frends . ')';
 }
}

its ok i got it working after doing some php manual referance

External image (may be gone) External image (may be gone)

External image (may be gone)

*****

**Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer.. Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free ***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close