I have data like this in mysql sort by id ASC:
NOTE: total is not in mysql, total is from price * total_item -> for example
id name total
---- ----------- ----------
1 item1 3
2 item2 5
3 item3 1
4 item4 2
5 item5 4
and I want to sort it in php
first, I sort the total to get the highest total in first place
//insert total into list
for($i=0;$i<5;$i++){
$total_list[] = $total;
$b = $total_list;
rsort($b);
//display total from highest to lowest
echo $b[$i];
}
the result will be like this:
id name total
---- ----------- ----------
1 item1 5
2 item2 4
3 item3 3
4 item4 2
5 item5 1
ok, I already got the total sorted according to my code above
so to get the name sorted too, I have to sort it but I already tried the same way as I sorted the total but the result is different
nah, I want the result is like this
id name total
---- ----------- ----------
1 item2 5
2 item5 4
3 item1 3
4 item4 2
5 item3 1