doddsey_65 Posted September 3, 2010 Share Posted September 3, 2010 I want a little online users list at the bottom of my page and the color of the username is to match the color defined in the database. but how do i get them to align side by side? if i add them to a <p> they will all appear under neath each other. Heres my current code: $sql=mysql_query("SELECT * FROM ".DB_PREFIX."members WHERE online = 1"); while ($row = mysql_fetch_object($sql)) { echo '<p style="color: #'.$row->username_color.';">'.$row->username.'</p>'; } also i want a comma at the end of each but how do i stop it adding a comma to the end of the last one? Quote Link to comment https://forums.phpfreaks.com/topic/212431-text-formatting/ Share on other sites More sharing options...
wildteen88 Posted September 3, 2010 Share Posted September 3, 2010 Don't, use <p> use an inline element such as <span> instead. To display the usernames in a comma delimited list there are different ways you can do this. Here are a few Option1 $usrers = ''; while ($row = mysql_fetch_object($sql)) $users .= '<span style="color: #'.$row->username_color.';">'.$row->username.'</span>, '; // removes the last two character from the end of the string (which will be the comma and a space) echo '<p>' . sub_str($users, 0, -2) . '</p>'; Or $users = array(); while ($row = mysql_fetch_object($sql)) $users[] = '<span style="color: #'.$row->username_color.';">'.$row->username.'</span>'; // add all users to the users array // implode the users into a comma delimited string. echo '<p>' . implode(', ', $users) . '</p>'; Quote Link to comment https://forums.phpfreaks.com/topic/212431-text-formatting/#findComment-1106784 Share on other sites More sharing options...
doddsey_65 Posted September 3, 2010 Author Share Posted September 3, 2010 thanks, works perfect. Quote Link to comment https://forums.phpfreaks.com/topic/212431-text-formatting/#findComment-1106788 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.