<?php
$query2 = QModel::query("SELECT * FROM transaction");
while($get2 = QModel::g($query2)) {
$totalprice = $get2['price'];
echo array_sum($totalprice);
}
?>
I get php error:
Message: array_sum() expects parameter 1 to be array, string given
please help thanks
you can use like this :
$totalprice += $get1['price'];
while($get2==Qmodel::query("select * from transaction"))
{
$totalprice[]=$get2['price'];
}
echo array_sum($totalprice);
while(..)
{
$totalpirce += $get2['price'];
}
Here you go:
<?php
$query2 = QModel::query('SELECT FROM transaction');
while($get2 = QModel::q($query2)){
$sum += $get2['price'];
}
echo $sum;
?>
Why not use SELECT transaction.*, SUM(price) as total_price FROM transaction
?
$totalprice=$get2['price];
=>incorrect way of define array $totalprice[]=$get2['price];
=>correct way of define array
$totalprice=array();
$query="";
while(condition){
$totalprice[]=$get2['price];
}echo array_sum($totalprice);