php - MySQL - Order by honor and write it in "for" together with username from different table -
i have 2 tables. player , stats. in player username , id. in stats honor , id. ids same in both tables. 1 player, 1 id. order stats honor , echo username table.
here try, can't order. player counter count of player. +1 reason starts 2
$getplayercounter = mysql_query("select `id` `player`"); $playercounter = mysql_num_rows($getplayercounter); ($i = 2; $i <= $playercounter + 1; $i++) { $username = mysql_query("select `player`.*, `stats`.* `player` inner join `stats` on `player`.`id`=$i , `stats`.`id`=$i") or die(mysql_error());; $fetch = mysql_fetch_assoc($username); echo "<tr>"; echo "<td>".$fetch['username']."</td>"; echo "<td>".$fetch['honor']."</td>"; echo "</tr>"; }
without using loop. how solution query sorted list already? kind of like:
select * player p join stats s on p.id = s.id order s.honor desc
where honor name of column stats value (hopefully it's column can sort number).
you array of rows ordered stats value in descending order (maximum value on top). can fetch row row in order in fetched array.
you walk through array doing this:
$result = mysql_query(the_query_above); while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['username']."</td>"; echo "<td>".$row['honor']."</td>"; echo "</tr>"; }
Comments
Post a Comment