我从数据库中提取数据,以表格中的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();
答案 0 :(得分:2)
在SQL查询中添加“ORDER BY (diamond/(stone+iron+gold)) DESC
”。