violinrocker Posted April 11, 2011 Share Posted April 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233369-echoes-only-1-row/ Share on other sites More sharing options...
Roman Fedorov Posted April 11, 2011 Share Posted April 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233369-echoes-only-1-row/#findComment-1200109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.