如何在PHP中反转 [英] How to reverse while in php
本文介绍了如何在PHP中反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张表,它简单地减去了从recv手机卖出的手机而不是在平衡手机中显示,并且还加上了旧行的平衡值。 c $ c | |收到的手机|我已售出的手机|平衡|
| 6 | 1 | 5
| 3 | 2 | 6
| 4 | 2 | 8 ---------->总手机我有
但是我想反转(计算从结尾开始)这个结果并且想要因为我想在顶部看到新的记录
|收到的手机|我已售出的手机|平衡|
| 6 | 1 | 8 ---------->总手机我有
| 3 | 2 | 3
| 4 | 2 | 2< ------- plus with recv mob 3 then - sold mob
我是($ fetch = mysql_fetch_array($ query)){
$ recvtotal + = $ {
$取[RECV];
$ soldtotal + = $ fetch [sold];
$结余+ = $ fetch [recv] - $ fetch [sold];
回显< tr>;
回显< td> 。 $ fetch [品牌]。 < / TD> 中;
回显< td> 。 $ fetch [recv]。 < / TD> 中;
回显< td> 。 $ fetch [sold]。 < / TD> 中;
回显< td> 。 ($平衡)。 < / TD> 中;
echo< / tr>;
}
解决方案
为什么不添加 排序 到您的查询?只需添加一个 ORDER BY
子句,您应该可以反转订单。
i have this table which simply minus sold mobiles from recv mobile than show in balance mobiles and also plus old row balance whith new row.
|Received Mobiles |Mobile i have sold | Balance |
|6 |1 | 5
|3 |2 | 6
|4 |2 | 8 ----------> total mobiles i have
but i want to reverse (calculation start from the end) this result and want to show like that because i want to see new records at top
|Received Mobiles |Mobile i have sold | Balance |
|6 |1 | 8 ----------> total mobiles i have
|3 |2 | 3
|4 |2 | 2 <------- plus with recv mob 3 then - sold mob
i am writing this
while ($fetch = mysql_fetch_array($query)) {
$recvtotal += $fetch[recv];
$soldtotal += $fetch[sold];
$balancing += $fetch[recv]-$fetch[sold];
echo "<tr>";
echo "<td>" . $fetch[brand] . "</td>";
echo "<td>" . $fetch[recv] . "</td>";
echo "<td>" . $fetch[sold] . "</td>";
echo "<td>" . ($balancing) . "</td>";
echo "</tr>";
}
解决方案
Why not add sorting to your query? Just add an ORDER BY
clause and you should be able invert the order.
这篇关于如何在PHP中反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文