SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: php loop

  1. #1
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there. i am running PHPBB here -

    http://www.hiphopmusic.co.uk/phpbb

    there is a loop at the bottom, that checks who is online, and if anyone is logged in, prints their usernames seperated by commas. However, the last username in the list (if anyone is logged in) still has a comma after it. How do i make it so that the last one in the list does not have a following comma.

    Code:
    $sql = "SELECT * FROM whosonline";
    if(!$result = mysql_query($sql, $db))
    	die("Error - Could not connect to the database</table></table></table>");
    if($myrow = mysql_fetch_array($result)) {
    	do {
    		
    		if(!stristr($myrow[username], "Guest")) {
    			$thisuser = get_userdata($myrow[username], $db);
    			echo "<font face='verdana' size='1'><a href=\"$url_phpbb/bb_profile.php?mode=view&user=$thisuser[user_id]\">$thisuser[username]</a></font>, \n";
    		}
    		else {
    			
    			if ($users_online==1) {
    			
    			echo "<font face='verdana' size='1'>There are no members browsing the forums, and $users_online guest. </font>\n";
    		break;
    		
    		}
    		
    		else {
    		echo "<font face='verdana' size='1'>There are no members browsing the forums, and $users_online guests. </font>\n";
    		break;
    		
    		}
    		
    		
    		
    		
    		
    		
    		
    		}
    		
    		
    	}
    Thanks
    j

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since I don't use the do {

    }

    function very much I chenged your code around a bit

    <?
    $sql = "SELECT * FROM whosonline";
    if(!$result = mysql_query($sql, $db)) {
    die("Error - Could not connect to the database</table></table></table>");
    }

    if($result) {
    $count = mysql_num_rows($result);
    $i = 1;
    while ($myrow = mysql_fetch_array($result)) {
    if(!stristr($myrow[username], "Guest")) {
    $thisuser = get_userdata($myrow[username], $db);

    if ($i == $count) {
    echo "<font face='verdana' size='1'><a href=\"$url_phpbb/bb_profile.php?mode=view&user=$thisuser[user_id]\">$thisuser[username]</a></font> \n";
    }
    else {
    echo "<font face='verdana' size='1'><a href=\"$url_phpbb/bb_profile.php?mode=view&user=$thisuser[user_id]\">$thisuser[username]</a></font>, \n";
    }


    }
    else {

    if ($users_online==1) {
    echo "<font face='verdana' size='1'>There are no members browsing the forums, and $users_online guest. </font>\n";
    break;
    }
    }
    $i++;
    }
    ?>

    [Edited by freddydoesphp on 10-26-2000 at 09:59 AM]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankyou very much


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •