[英]Simplest/fastest way of ordering mysql output in php
I am pulling data from database to show it with PHP in table. 我从数据库中提取数据,用表格中的PHP显示它。 How to show this data descending from x-level from highest to lowest?
如何显示此数据从x级别从最高到最低?
An example output of code given below is 下面给出的代码示例输出是
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();
将“ ORDER BY (diamond/(stone+iron+gold)) DESC
”添加到您的SQL查询中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.