SQL_Query Username Block help

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   SQL_Query Username Block help
lilc420
CZ Newbie
 Codezwiz Site Donator
lilc420 has been a member for over 17 year's 17 Year Member
usa.gif
Age: 48
Website:
Status: Offline
Joined: Oct 11, 2007
0.00 posts per day
Posts: 3
Points: 525
   
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.

//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.


Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,440
   
To list multiple results you will need to either put them into an array or pull them in a loop.

Loop example:


$content ="<BR><center>Who's Chatting:<BR> ";
//Function to call users in chat
$user_display = 'SELECT * FROM '.$prefix.'_live_online ORDER BY `username` ASC';
$online_results = $db->sql_query($user_display);
while(list($chat_users_online) = $db->sql_fetchrow($online_results)) {
   $content .= $chat_users_online['username'];
}
$content .="</center>";


Array Example:


$user_display = 'SELECT * FROM '.$prefix.'_live_online ORDER BY `username` ASC';
$online_results = $db->sql_query($user_display);
while(list($chat_users_online) = $db->sql_fetchrow($online_results)) {
   $row[] = $chat_users_online;
}
$content ="<BR><center>Who's Chatting:<BR> ";
//Function to call users in chat
for ($i = 0; $i <count($row); $i++) {
   $content .= $row[$i]['username'];
}
$content .="</center>";


The loop example might be the easiest for to use.



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   
lilc420
CZ Newbie
 Codezwiz Site Donator
lilc420 has been a member for over 17 year's 17 Year Member
usa.gif
Age: 48
Website:
Status: Offline
Joined: Oct 11, 2007
0.00 posts per day
Posts: 3
Points: 525
   
Sweet.. works like a champ.. thanks.



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
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 cannot attach files in this forum
You cannot download files in this forum