0

我正在从数据库中提取数据以在表中使用 PHP 显示它。如何显示从 x 级别从最高到最低的数据?

下面给出的代码示例输出是

在此处输入图像描述

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();
4

1 回答 1

2

将“ ORDER BY (diamond/(stone+iron+gold)) DESC”添加到您的 SQL 查询中。

于 2012-07-29T20:32:55.307 回答