Jump to content

Recommended Posts

i have this function

function friends($info) { mysql_connect("localhost", "kiphi", "bncorjnn") or die(mysql_error());
					mysql_select_db("kiphi_comments") or die(mysql_error());
					$count = "SELECT COUNT(*) as num FROM friend_requests where username='$info'"; 
					$count2 = mysql_fetch_array(mysql_query($count));
$ol2 = "SELECT * FROM friends INNER JOIN active_users ON friends.friendname=active_users.username where friends.username='$info'"; 
$fetchol= mysql_query($ol2) or die("Could not get threads");
					while ($online = mysql_fetch_array($fetchol)){
					$friend['online'] = $online[friendname];}

					return $friend;}

 

and then i use this to call the function above

$friend=friends($session->username);   echo $friend['online'];

 

what it does is checks the active users and then compares it to your friend list and then echo those friends that are online, problem is it only shows 1. i tried the Count(*) and it shows 3. i think i need to use, 'while' but i dont know where to put it

Link to comment
https://forums.phpfreaks.com/topic/233369-echoes-only-1-row/
Share on other sites

Hi,

making the

$friend['online'] = $online[friendname];

you overwrite always the same variable, so the only friend that you will return will be the last one.

you should do

$friend[] = $online[friendname];

and to print them use foreach statement

 

in this case the function will return the array of the names

Link to comment
https://forums.phpfreaks.com/topic/233369-echoes-only-1-row/#findComment-1200109
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.