我只是一个新手,我已经尽力弄清楚如何解决我的问题,但我真的无法得到它。
我只想知道如何在循环中获取当前行的primary key/foreign key
值。在我当前的代码中,我得到了最后一行的primary key
。我尝试了$_POST[subject_id]
和$_SESSION[subject_id]
但没有任何反应。
请帮我。我该怎么办?提前谢谢!
这是我的php文件。
dbconn();
$sql = "select student_id, lastname ||', '|| firstname ||' '|| middlename as
name, contact_no from tbl_student where student_id in (select student_id
from tbl_student_block)";
dbclose();
echo "<center>";
insertListMenu ("Select Student: ", "student", $sql." order by name",
"student_id", "name", "StudSearch", "Search");
echo "</center>";
echo "<br/>";
$student_id = $_POST['student'];
if (($_POST['StudSearch']) == 'Search'){
dbconn();
$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 = ".$student_id."
group by sj.subject_id order by sj.subject_id;");
displayRecordset($rs);
dbclose();
}
$_SESSION['studID'] = $_POST['student'];
if (isset($_POST['Payment']) && ($_POST['Payment'] == 'Add Payment')){
dbconn();
$rsbookedit = pg_query("select sj.description, sj.subject_fee,
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 = ".$_SESSION['studID']." and
sb.subject_id = '".$_SESSION['subID']."' group by sj.subject_id
order by sj.subject_id;");
$r2 = pg_fetch_array($rsbookedit, NULL, PGSQL_ASSOC);
echo var_dump($r2);
dbclose();
}
这是我的循环:
<?php
$counter = 1;
while ($r = pg_fetch_array($rs, NULL, PGSQL_ASSOC)){
?>
<tr>
<td><?php echo $counter; ?></td>
<td><?php echo $r['subject_id']; ?></td>
<td><?php echo $r['subject_fee']; ?></td>
<td><?php echo $r['total']; ?></td>
<td><?php echo $r['balance']; ?></td>
<td>
<?php
if ($r['balance'] > 0){
?>
<input type="submit" name="Payment" value="Add Payment" />
<?php
}
else
echo "PAID";
?>
</td>
</tr>
<?php
$_SESSION['subID'] = $r['subject_id'];
$counter++;
}
?>
答案 0 :(得分:0)
尝试PGSQL_BOTH on the line
或者您可以将该参数留空,因为它是可选的
while ($r = pg_fetch_array($rs, NULL, PGSQL_BOTH)){