takn25 Posted March 31, 2011 Share Posted March 31, 2011 Hi, I was wondering is this possible in an easy way or do I have to come up with something else ^^. I have a row called Rate and I am echoing something like this $query="SELECT * FROM clan ORDER BY rate DESC"; Which is going fine but now I want to know is there any way of echoing for example the highest rate in mysql is 1800 I want to echo 1 next to it showing this is coming first second is 1782 echo 2 next to it and so on. A bit difficult to explain for what I am trying to achieve mostly I want to echo 1,2,3,4,5 depending on which rate has the highest number The higher the rating the lower the number an example below I hope I made some sense. 1 = 1800 2 = 1782 3 = 1600 4 = 1500 Link to comment https://forums.phpfreaks.com/topic/232285-a-little-help/ Share on other sites More sharing options...
betterphp Posted March 31, 2011 Share Posted March 31, 2011 inside your while loop you could just have an incrementing variable that starts at 1 Link to comment https://forums.phpfreaks.com/topic/232285-a-little-help/#findComment-1194971 Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 In the event you have records with equal ratings you would need to track that ie 1 = 1800 2 = 1735 2 = 1735 3 = 1500 ect $query="SELECT * FROM clan ORDER BY rate DESC"; $result = mysql_query($query); $i=0; $last_rate = 0; while($row = mysql_fetch_array($result)) { $current_rate = $row['rate']; if($current_rate != $last_rate) { $i++; } echo $i . " = " . $current_rate . "</br/>"; $last_rate = $current_rate; } Link to comment https://forums.phpfreaks.com/topic/232285-a-little-help/#findComment-1195004 Share on other sites More sharing options...
takn25 Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks works as desired! Link to comment https://forums.phpfreaks.com/topic/232285-a-little-help/#findComment-1195033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.