Get last row value from PHP ADODB MySQL loop -
i trying last row value select query.
this php query using adodb:
$con->execute("set @depos=0"); $con->execute("set @total=$openingbalance"); $sql = "select if( credit >0, @depos := credit , @depos := @depos + credit - debit ) depos_bal, @total := @total + `credit` - `debit` net_bal `table` `mydate` < '".$monthstarts."' order `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; here want fetch last row value loop.
for example:
balance ---------- 150.00 250.00 350.00 600.00 850.52 <----- row want fetch query. how can fetch this? kindly help!
no need of loop try this:-
$fnew = $ssresults->getrows(); $bal = $fnew[count($fnew)-1]['net_bal']; echo $bal; note:- count give total number of element present in array. , array index start 0 count($fnew)-1 give last record. thanks.
Comments
Post a Comment