【问题标题】:Get last row value from PHP ADODB MySQL loop从 PHP ADODB MySQL 循环中获取最后一行值
【发布时间】:2015-05-31 06:21:47
【问题描述】:

我正在尝试从我的选择查询中获取最后一行的值。

这是我使用 ADODB 的 PHP 查询:

$con->Execute("SET @depos=0");
$con->Execute("SET @total=$openingbalance");
$sql = "SELECT if( credit >0, @depos := credit , @depos := @depos + credit - debit ) AS depos_bal, @total := @total + `credit` - `debit` AS net_bal FROM `table` WHERE `mydate` < '".$monthstarts."' ORDER BY `mydate` ASC, `credit` DESC";
    $ssresults=$con->Execute($sql);
    $fnew = $ssresults->getrows();

    for($i=0;$i<count($fnew);$i++)
    {
        $bal = $fnew[$i]['net_bal'];
    }
 echo $bal;

这里我想从循环中获取最后一行的值。

例如:

 Balance
 ----------
 150.00
 250.00
 350.00
 600.00
 850.52 <----- this is the row I want to fetch from the query.

我怎样才能得到这个?请帮忙!

【问题讨论】:

    标签: php mysql adodb


    【解决方案1】:

    不需要for循环试试这个:-

    $fnew = $ssresults->getrows();
    
    $bal = $fnew[count($fnew)-1]['net_bal'];
    
     echo $bal;
    

    注意:- count 给出数组中元素的总数。数组索引从0 开始,所以count($fnew)-1 给你最后一条记录。谢谢。

    【讨论】:

    • 什么是硬币?你的意思是计数?
    • 是的,没有得到想要的结果... net_bal 总结所有行
    • 那么它返回的金额是多少?
    • 既然是在贷方和借方中加减,我应该循环得到想要的结果
    • 请处理它.. 给我一些时间,我也在尝试其他的东西。会在某个时候更新相同的
    猜你喜欢
    • 2011-01-17
    • 2017-12-06
    • 2018-12-29
    • 2015-03-10
    • 2016-01-31
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多