php - 我如何在 php 中从 mysql 查询结果组按日期给出符号(如更改颜色或 fa-up/fa-down)
问题描述
预期:如果 osl 高于之前的日期,则回显“fa-up”。
<?php $sql_nongadai_kol_kw2= mysqli_query($kon,"SELECT * FROM vw_nongadai_kanwil ORDER BY TGL_UPDATE DESC LIMIT 31"); ?>
<?php foreach( $sql_nongadai_kol_kw2 as $print ){;
$tanda ='tes';
$osl_tes =$print['osl_total'];
if ($osl_tes > $osl_tes) {$tanda = '<i class="fa fa-long-arrow-up"></i>';}
elseif ($osl_tes < $osl_tes) {$tanda = '<i class="fa fa-long-arrow-down"></i>';}
elseif ($osl_tes = $osl_tes) {$tanda = '<i class="fa fa-long-arrow-v"></i>';}
else {$tanda = 'error';}
?>
<tr>
<th scope="row"><?php echo $print['tgl_update'];?></th>
<td align="right"><?php echo $tanda;?> - <?php echo number_format($print['osl_total']); ?></td>
</tr>
<?php } ;?>
解决方案
您应该$osl_tes
在 foreach 循环之前启动,在循环内比较$osl_tes
并将$print['osl_total']
新值绑定到$osl_tes
:
<?php
$sql_nongadai_kol_kw2= mysqli_query($kon,"SELECT * FROM vw_nongadai_kanwil ORDER BY TGL_UPDATE DESC LIMIT 31");
$osl_tes = 0; // or some other initial value
?>
<?php foreach( $sql_nongadai_kol_kw2 as $print ){;
$tanda ='tes';
if ($print['osl_total'] > $osl_tes) {$tanda = '<i class="fa fa-long-arrow-up"></i>';}
elseif ($print['osl_total'] < $osl_tes) {$tanda = '<i class="fa fa-long-arrow-down"></i>';}
elseif ($print['osl_total'] = $osl_tes) {$tanda = '<i class="fa fa-long-arrow-v"></i>';}
else {$tanda = 'error';}
$osl_tes = $print['osl_total']; // bind new value
?>
<tr>
<th scope="row"><?php echo $print['tgl_update'];?></th>
<td align="right"><?php echo $tanda;?> - <?php echo number_format($print['osl_total']); ?></td>
</tr>
<?php } ;?>
推荐阅读
- macos - MacOS 真实睡眠检测
- html - 单击按钮时显示模态 Boostrap
- ibm-mq - Payara SSL 队列连接
- android - java.lang.VerfyError:在 Android 11 中发送电子邮件
- powershell - 来自 C# 控制台应用程序的标准输出字符串
- python - 绘图时升序 df 显示为降序
- javascript - 在共享文件夹中旁加载 Office 加载项,插入我的加载项中没有可用的加载项
- javascript - 我想在 Nuxt.js 中使用 Filter 缩小范围后进行排序
- elasticsearch - Elasticsearch 聚合和过滤器返回不同的大小
- slack - 有没有办法在 Slack 中安装一个仅对安装它的用户可用的应用程序。(个人范围内的应用安装)