<?php
$query2 = QModel::query("SELECT * FROM transaction");
while($get2 = QModel::g($query2)) {
$totalprice = $get2['price'];
echo array_sum($totalprice);
}
?>
我得到 php 错误:
消息:array_sum() 期望参数 1 是数组,给定字符串
请帮忙谢谢
你可以这样使用:
$totalprice += $get1['price'];
while($get2==Qmodel::query("select * from transaction"))
{
$totalprice[]=$get2['price'];
}
echo array_sum($totalprice);
while(..)
{
$totalpirce += $get2['price'];
}
干得好:
<?php
$query2 = QModel::query('SELECT FROM transaction');
while($get2 = QModel::q($query2)){
$sum += $get2['price'];
}
echo $sum;
?>
为什么不使用SELECT transaction.*, SUM(price) as total_price FROM transaction
?
$totalprice=$get2['price];
=>定义数组的方法不正确
$totalprice[]=$get2['price];
=>定义数组的正确方法
$totalprice=array();
$query="";
while(condition){
$totalprice[]=$get2['price];
}echo array_sum($totalprice);