Ashoar Posted April 9, 2009 Share Posted April 9, 2009 I have this small section of code. I am fetching data from a MYSQL row and wan't to display every entry in there. Normally this worlks fine but for some reason this method isn't working. Here is the bit of code: $online = mysql_query("SELECT username FROM online") or die(mysql_error()); $userrows = mysql_num_rows($online); for($count = 1; $count <= $userrows; $count++) { $name = mysql_fetch_array($online); print "<tr class='mainrow'><td>Currently active: <A href='member_profile.php?username=$name[username]'>$name[username]</a></td></tr>"; } print "</table>"; When i check, it only displays one entry and not all of them. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 9, 2009 Share Posted April 9, 2009 For looping through mysql results use a while loop rather than a for loop $online = mysql_query("SELECT username FROM online") or die(mysql_error()); if(mysql_num_rows($online) > 0) { while($row = mysql_fetch_assoc($online)) { $online[] = '<A href="member_profile.php?username='.$row['username'].'">'.$row['username'].'</a>'; } echo '<tr class="mainrow"><td>Currently active: ' . implode(',', $online) . '</td></tr>'; } else { echo '<tr class="mainrow"><td>There are currently no users logged in</td></tr>'; } echo '</table>'; Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 9, 2009 Author Share Posted April 9, 2009 Ah that is it. Thank you for the help. Quote Link to comment 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.