我正在尝试获取 php 内一列中的值的总和,但它根本不工作,而在 MySQL 中测试时查询工作正常这是代码(使用完整代码更新)
require('../_req/base.php');
$getCartQ = "select * from user_product inner join cart inner join products inner join users on user_product.User_ID = cart.User_ID and user_product.User_ID = users.User_ID group by cart.User_ID";
$getCartR = mysql_query($getCartQ);
?> <table align="center" width="1271" border="0" cellpadding="0" cellspacing="0">
<?php
while($cartRow = mysql_fetch_array($getCartR)){
$sumQ = "select SUM(Total) as total from user_product where Status = 'active' and user_product.User_ID = '$cartRow[User_ID]'";
$sumR = mysql_query($sumQ) or die(mysql_error());
$sumRow = mysql_fetch_assoc($sumR);
$cost = $sumRow['total'];
?>
<tr>
<td><?php echo $cartRow['Full_Name'] ?></td>
<td><?php echo $cartRow['State']; ?></td>
<td><?php echo $cost; ?></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close($connect);
当我尝试回显 $cost 时,我什么也没得到,只是一个空格该代码有什么问题?