【发布时间】:2020-10-01 03:41:35
【问题描述】:
以下代码:
<?php
echo "<h3>Result</h3>";
$attribute1 = mysqli_query($conn, "SELECT min(c1) as min1, max(c2) as max1, max(c3) as max2 from tb_alternative");
$atr1 = mysqli_fetch_array($attribute1);
$sql3 = mysqli_query($conn, "SELECT * from tb_alternative");
while($r3 = mysqli_fetch_array($sql3, MYSQLI_ASSOC)){
$point = ((($atr1['min1']/$r3['c1'])*$bobot[0])+
(($r3['c2']/$atr1['max1'])*$bobot[1])+
(($r3['c3']/$atr1['max2'])*$bobot[2]));
?>
<tr>
<td><?php echo $r3['id']?></td>
<td><?php echo $r3['alternative']?></td>
<td><?php echo $point?></td>
</tr>
<?php
}
?>
结果:
如何按总分对数据进行排序?,总分是计算出来的,不是从数据库中计算出来的
【问题讨论】:
-
php.net/manual/en/function.usort.php。或者在查询中进行计算并在那里排序。
-
我认为您正在寻找 SQL 排序。
-
不能在 MySQL 中完成,因为
$bobot不是 SQL 结果的一部分 -
@SlavaRozhnev 当然可以。在查询中包含
$bobot的值。