无法将列SUM(column_name)作为Total回显

时间:2014-03-10 12:26:29

标签: php sql

这是我的疑问:

$rs = pg_query("select sj.*, SUM(p.paid_amount) as Total, sj.subject_fee - SUM(p.paid_amount) as Balance
                from tbl_subject as sj, tbl_payment_details as p, tbl_student as s, tbl_student_block as sb
                where p.student_block_id = sb.student_block_id and s.student_id = sb.student_id and sj.subject_id = sb.subject_id and
                sb.student_id = ".$_POST['student']." group by sj.subject_id order by sj.subject_id;");
displayRecordset($rs);

问题是,当我回显$r['Total']时,它不会在我的查询中显示列总计。

这是我的功能:

$counter = 1;
while ($r = pg_fetch_array($rs, NULL, PGSQL_ASSOC))
{
$total = $r['Total'];
?>
  <tr>
    <td><?php echo $counter; ?></td>
    <td><?php echo $r['subject_id']; ?></td>
    <td><?php echo $r['subject_fee']; ?></td>
    <td><?php echo $total; ?></td>
    <td><?php echo  $r['Balance']."Balance"; ?></td>
    <td>
        <a href="<?php echo $_SERVER['PHP_SELF']."?subject_id=".$r['subject_id'];?>">Edit</a>
    </td>
  </tr>
<?php
    $counter++;
}

0 个答案:

没有答案