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. Link to comment https://forums.phpfreaks.com/topic/153299-solved-array-problem/ 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>'; Link to comment https://forums.phpfreaks.com/topic/153299-solved-array-problem/#findComment-805360 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. Link to comment https://forums.phpfreaks.com/topic/153299-solved-array-problem/#findComment-805362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.