Rackover Rackover - 1 year ago 75
SQL Question

SQL SELECT * returns only one row

I'm designing a website and I wrote some webpage that display the list of users.
I used to do a

$query = SELECT * FROM `table_users` WHERE `id`='.$id.'

and then increment the ID with a "while" so I can grab all the users. But it's too slow now, and it glitches when there is a gap between IDs.

So I tried something like

$query = SELECT `name` FROM `tbl_user`ORDER BY `id`

and displaying the userlist with a

while ($i < sizeof(mysql_fetch_array(mysql_query($query)))){
<code to display an user>

But the mysql_fetch_array only returnes one user, the first one (the one with the littliest ID). I want it to return all users in an array. How do I do ?

Answer Source

Try This

$query = "SELECT `name` FROM `tbl_user` ORDER BY `id`";
$user_query = mysql_query($query);

while ($row = mysql_fetch_array($user_query)){
  echo $i." : ".$row['name']."<br>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download