IlikeITalot
IlikeITalot

Reputation: 51

Simplest/fastest way of ordering mysql output in php

I am pulling data from database to show it with PHP in table. How to show this data descending from x-level from highest to lowest?

An example output of code given below is

enter image description here

function check() {

    $function_Query="SELECT user, stone, iron, gold, diamond FROM xraydeath WHERE (diamond/(stone+iron+gold)) >= 0.03";
    $function_Ask = mysql_query($function_Query) or die(mysql_error());

        echo '<table cellpadding="5">
        <tr align="center">
        <td><strong>user</strong></td>
        <td><strong>x-level</strong></td>
        <td><strong>stone</strong></td>
        <td><strong>iron</strong></td>
        <td><strong>gold</strong></td>
        <td><strong>diamond</strong></td>
        </tr>';

    while($function_Result = mysql_fetch_array($function_Ask)){

        $user = $function_Result['user'];
        $stone = $function_Result['stone'];
        $iron = $function_Result['iron'];
        $gold = $function_Result['gold'];
        $diamond = $function_Result['diamond'];
        $level = round(($diamond / ($stone + $iron + $gold)), 4) * 100;

        echo '<tr>';
        echo '<td>' . $user . '</td>
              <td>' . $level . '</td>
              <td>' . $stone . '</td>
              <td>' . $iron . '</td>
              <td>' . $gold . '</td>
              <td>' . $diamond . '</td>';

        echo '</tr>';

            }
echo '</tr></table>';

}

check();

Upvotes: 0

Views: 187

Answers (1)

Lusitanian
Lusitanian

Reputation: 11122

Add " ORDER BY (diamond/(stone+iron+gold)) DESC" to your SQL query.

Upvotes: 2

Related Questions