Maximus Posted March 6, 2007 Share Posted March 6, 2007 Hi, I am trying to retrieve 10 entries with the highest value in field "votes". $result = mysql_query("SELECT * FROM `sites` ORDER BY `votes` ASC LIMIT 0,10"); while($g = mysql_fetch_array($result)) { echo '<br>'.$g['name'].' - '.$g['votes'].' Votes</a>'; } The code above displays ten entries, but doesn't but them in order from high to low. I don't understand... The output looks like this: dsgdsg - 0 Votes dgds - 0 Votes omg lol - 0 Votes gkjkfgs - 0 Votes fhfd - 0 Votes lhhgllk - 0 Votes dfhjdfj - 2434 Votes test - 5 Votes gjdfd - 5765 Votes fjdgdd- 64 Votes Ignore the phony names, but rather focus on the order of the "votes"...its really weird. Link to comment https://forums.phpfreaks.com/topic/41360-solved-mysql-order-by-not-working/ Share on other sites More sharing options...
AndyB Posted March 6, 2007 Share Posted March 6, 2007 My bet is that the field votes is a text (or varchar) field instead of a numeric field. Link to comment https://forums.phpfreaks.com/topic/41360-solved-mysql-order-by-not-working/#findComment-200419 Share on other sites More sharing options...
Maximus Posted March 6, 2007 Author Share Posted March 6, 2007 You're right, it is a varchar field. I changed it (in table structure) to "INT" and now it works perfectly. Thanks so much! Link to comment https://forums.phpfreaks.com/topic/41360-solved-mysql-order-by-not-working/#findComment-200430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.