时间:2021-07-01 10:21:17 帮助过:20人阅读
$sa='select * from pql_spices_class order by id asc'; $ra=mysql_query($sa); $i=1; while($rsa=mysql_fetch_array($ra,MYSQL_ASSOC)) { //echo $rsa['classname'].",".$rsa['id']."
"; $cid = $rsa['id']; $resf=mysql_query('SELECT * FROM `pql_spices` where classid='.$cid.' ORDER BY id DESC'); while($rsf=mysql_fetch_array($resf)) { $Prices+=$rsf['Price']; } echo $i."、".$rsa['classname'].":".$Prices."元,"; $i++; }
你的 $Prices 总是累加没有清0,自然就是现在的结果
再说一个分组求和的查询指令就可完成的事情,为何要用循环累加完成?
请问要怎么清零呢?
题外话:为什么论坛回复点引用没有反应?
$sa='select * from pql_spices_class order by id asc';
$ra=mysql_query($sa);
$i=1;
while($rsa=mysql_fetch_array($ra,MYSQL_ASSOC))
{
[color="red"]$Prices=0;//这里清零[/color]
//echo $rsa['classname'].",".$rsa['id']."
";
$cid = $rsa['id'];
$resf=mysql_query('SELECT * FROM `pql_spices` where classid='.$cid.' ORDER BY id DESC');
while($rsf=mysql_fetch_array($resf))
{
$Prices+=$rsf['Price'];
}
echo $i."、".$rsa['classname'].":".$Prices."元,";
$i++;
}
哦哦,今天又犯傻了。谢谢了,两位。