dtu1747 2011-01-21 11:00
浏览 37
已采纳

PHP计算while循环中两个值之间的差异

I'm outputting an XML document with PHP from mysql results, in one column I have a bunch of values, but these are accumulative values, i.e.: 1,3,6,8,12,45,etc...but how can I only echo out the difference between values rather than the values themselves in this:

while($row = mysql_fetch_array($result)){
    $strXML .= "<set name='".date("G:i:s", strtotime($row["tstamp"]))
            .  "' value='".$row['steam']."' color='AFD8F8' />";
}

The column in question is "steam", how could I go about doing this?

  • 写回答

2条回答 默认 最新

  • douzhou7124 2011-01-21 11:09
    关注

    Do you want to do this?

    $previous = 0;
    while($row = mysql_fetch_array($result)){
        $difference = $row['steam'] - $previous;
        $strXML .= "<set name='".date("G:i:s", strtotime($row["tstamp"]))
                .  "' value='".$difference."' color='AFD8F8' />";
        $previous = $row['steam'];
    }
    

    assuming $row['steam'] is a single number, not a comma separated list.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度