php - 在 php 中获取列的总和不起作用

标签 php mysql sum

我试图获取 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 时,我什么也没有得到,只是一个空格,该代码有什么问题?

最佳答案

 user_product.User_ID = '$getCartR[User_ID]'";

 user_product.User_ID = '{$getCartR['User_ID']}'";

关于php - 在 php 中获取列的总和不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16614069/

相关文章:

php - 查找白色像素线

php - mysql按日期排序

undefined variable 的 php 通知 & 试图获取非对象的属性

php - XML 到数据库,我应该走什么路线?

mysql 我怎样才能得到这样一个甲酸年 :month:day 的日期差异结果

mysql - 根据具有多个记录的表中另一列的不同值添加值

function - 在函数中进行子集化以计算行总计

vba - 对范围求和并格式化求和错误

PHP-Laravel 依赖注入(inject) : pass parameters to dependency constructor

php - 使用 JOIN 包含 NULL 值