PDA

View Full Version : PHP help, displaying SQL results



Hitman
11-06-2009, 07:28 PM
Howdy. Basically this is annoying me now... I'm making a leader board. It uses a mysql query to get the top 10 highest scores and then display them in a table... I'm stuck at displaying them all.

I can get the first one, but the rest are the same as the first... I've looked on google but I can't find it... it needs to loop or whatever, but I'm not too sure how.


$get = mysql_query("SELECT * FROM `users` ORDER BY `cash` DESC LIMIT 0 , 10 ");
$get = mysql_fetch_array($get);
echo "<table width=\"200\" border=\"1\">
<tr>
<td>".$get['username']."</td>
<td>".$get['cash']."</td>
</tr>
</table>";

If somebody could post a code so that it could loop it and display all 10 I'd be grateful.

Thanks.

Dentafrice
11-06-2009, 07:35 PM
$get = mysql_query("SELECT * FROM `users` ORDER BY `cash` DESC LIMIT 0,10");

echo '<table width="200" border="1">';

while($row = mysql_fetch_array($get)) {
echo '<tr>';
echo '<td>' . $row["username"] . '</td>';
echo '<td>' . $row["cash"] . '</td>';
echo '</tr>';
}

echo '</table>';
Should work, I did it in text edit so it may.

Hitman
11-06-2009, 07:38 PM
I love you Caleb. Works perfectly, thanks ever so much!

Want to hide these adverts? Register an account for free!