Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
lilc420
New Member
New Member



Joined: Feb 02, 2007
Posts: 24

PostPosted: Sat Jun 21, 2008 7:09 pm Reply with quote

I am trying to create a block to show the current users in our chat module. I can get it to show the first person Alphabetically, but it will not list the rest. Here is the code I have currently.

Code:
//Function to call users in chat

$user_display = 'SELECT * FROM '.$prefix.'_live_online ORDER BY '.$prefix.'_live_online.`username` ASC';
$online_results = $db->sql_query($user_display);
list($chat_users_online) = $db->sql_fetchrow($online_results);

$content ="<BR><center>Who's Chatting:<BR> ";
$content .=$chat_users_online;
$content .="</center>";



Anyone know what commands I need to use to show more than the first person? Thanks.
 
View user's profile Send private message
evaders99
Former Moderator in Good Standing



Joined: Apr 30, 2004
Posts: 3221

PostPosted: Sat Jun 21, 2008 8:53 pm Reply with quote

You will need a while loop to go through every row with sql_fetchrow until there are no more returned. There are numerous examples on how to do this in PHP

_________________
- Star Wars Rebellion Network -

Need help? Nuke Patched Core, Coding Services, Webmaster Services 
View user's profile Send private message Visit poster's website
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Sat Jun 21, 2008 9:58 pm Reply with quote

something like this,

Code:


global $prefix, $db;
//Function to call users in chat
$user_display = 'SELECT username FROM '.$prefix.'_live_online ORDER BY username DESC LIMIT 0,5';
$results = $db->sql_query($user_display);
$content ="<br /><center><strong>Who's Chatting:</strong><br /><br /> ";
if ($db->sql_numrows($result)) {
   while (list($username) = $db->sql_fetchrow($result)) {
   $content .= '<div>'.$username.'</div>';
   }
   } else {
   $content .= 'No Ones Chatting';
   }
   $content .="</center>";
 
View user's profile Send private message
lilc420







PostPosted: Sun Jun 22, 2008 9:15 am Reply with quote

You are awesome testy1... that worked like a charm.

I was racking my brain searching for the structure to accomplish this.
 
testy1







PostPosted: Sun Jun 22, 2008 3:52 pm Reply with quote

even though i know how to use "while" it's one of those things that i always stuff up and have to go back and check lol, glad it worked

the only thing to change will be how many it displays, if you want more than 5 change the 5 below to how ever many you want .

Code:


LIMIT 0,5
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©