View Full Version : MySQL Numbers
Robbie
03-02-2008, 07:11 PM
I have a database where users send in a name like 'Dave' and I want to display the top 5 names voted for. I know I could use mysql_num_rows to get the number of times a name has been voted for, but how would I display the top 5 names using mysql_num_rows?
+rep to helpers ;)
Robbie
03-02-2008, 09:55 PM
right, ive sorta figured it but it displays it like this
Red has been voted for 2 times
Red has been voted for 2 times
Blue has been voted for 1 times
the code is
$query = "SELECT * FROM `colours` ";
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query");
$numrows = mysql_num_rows($result);
echo '';
while($row = mysql_fetch_array($result)) {
$color = $row["color"];
$query2 = "SELECT * FROM `colours` WHERE `color` = '$color'";
$result2 = mysql_query($query2) or die (mysql_error()."<br />Couldn't execute query: $query");
$numrows2 = mysql_num_rows($result2);
echo "$color has been voted for $numrows2 times<br>";
}
any help? thanks
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.