refiking Posted March 21, 2008 Share Posted March 21, 2008 I am running a script that checks returns the records in a table by the rank descending down. But, when there are 2 people with the same rank, how can I get it to show me the first record with that rank? Here is the snippet: <? include 'cont.php'; $result = mysql_query("SELECT tag FROM recruits ORDER BY rank DESC"); while($row = mysql_fetch_array($result)) { $tag = $row['tag']; ?><font color="silver"> <strong><?echo $tag."<br>";}?></strong></font> </td></table> </body> Link to comment https://forums.phpfreaks.com/topic/97303-can-i-order-a-db-search-by-two-factors/ Share on other sites More sharing options...
cooldude832 Posted March 21, 2008 Share Posted March 21, 2008 I let you make that decision http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html Link to comment https://forums.phpfreaks.com/topic/97303-can-i-order-a-db-search-by-two-factors/#findComment-497969 Share on other sites More sharing options...
Barand Posted March 22, 2008 Share Posted March 22, 2008 how can I get it to show me the first record with that rank? Define "first" Link to comment https://forums.phpfreaks.com/topic/97303-can-i-order-a-db-search-by-two-factors/#findComment-497987 Share on other sites More sharing options...
refiking Posted March 22, 2008 Author Share Posted March 22, 2008 What I mean by first is the first record that was actually inserted into the table. For example, if Bill inserted a record on Monday and Rex inserted a record on Wednesday and both have a rank of 250, how can I get it to show Bill before Rex? Link to comment https://forums.phpfreaks.com/topic/97303-can-i-order-a-db-search-by-two-factors/#findComment-498000 Share on other sites More sharing options...
marun Posted March 22, 2008 Share Posted March 22, 2008 Add date filed to the database and sort result by date. Link to comment https://forums.phpfreaks.com/topic/97303-can-i-order-a-db-search-by-two-factors/#findComment-498016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.