Jump to content

[SOLVED] showing a list .. 1,2,3,4 and stoping a comma been added on the end?


runnerjp

Recommended Posts

im shoing a list of users

 

 print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,";

 

and i feel it would look nicer if the comma was not on the end of the last one... i know i could use an if statement to show just a name if there is just one user but what if there is more... how would i prevent the comma been shown?

Link to comment
Share on other sites

nope no loop... full code is as shows..

 

<?php
$getusersonline="SELECT user_id,user FROM useronline 
   WHERE 
file = 'http://www.runningprofiles.com/members/index.php?page=forum&forum=$forum' AND
  timestamp > " . (time() - 900) ; //grab from sql users on in last 15 minutes
$getusersonline2=mysql_query($getusersonline) or die("Could not get users");
$num=mysql_num_rows($getusersonline2);

echo "<b>There " . ($num != 1 ? "are" : "is") . " $num user" . ($num != 1 ? "s" : "") . " currently viewing the $forum board: </B>";

while($getusersonline3=mysql_fetch_array($getusersonline2))
{
  print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,";
}

?>

 

would there be a better way of doing this?

 

also would i just add print implode(',',$users);

Link to comment
Share on other sites

As rhodesa said, just replace:

<?php
while($getusersonline3=mysql_fetch_array($getusersonline2))
{
  print "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>,";
}
?>

with

<?php
$tmp = array();
while($getusersonline3=mysql_fetch_array($getusersonline2))
{
  $tmp[] = "<A href='$getusersonline3[user]'>$getusersonline3[user]</a>";
}
echo implode(',',$tmp);
?>

 

Ken

Link to comment
Share on other sites

Yo Jaret :P guess who!

 

Just load all the userids into an array and then use the imlpode function.

 

while($getusersonline3=mysql_fetch_array($getusersonline2))
{
  $UserIDs = $getusersonline3[user]; 
}
echo implode(',',$UserIDs );

 

edit

Haha, I was beaten twice and missed the []s off UserIDs ^^;

Link to comment
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.