【问题标题】:how can i give sign (like change color or fa-up/fa-down) in php from mysql query result group by date我如何在 php 中从 mysql 查询结果组按日期给出符号(如更改颜色或 fa-up/fa-down)
【发布时间】:2021-10-23 00:35:58
【问题描述】:

预期:如果 osl 高于之前的日期,则 echo '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 } ;?>

【问题讨论】:

    标签: php html css mysql


    【解决方案1】:

    您应该在 foreach 循环之前启动 $osl_tes,在循环内比较 $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 } ;?>
    

    【讨论】:

    猜你喜欢
    • 2014-12-19
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多