gpt4 book ai didi

PHP 循环行值

转载 作者:行者123 更新时间:2023-11-30 00:34:12 24 4
gpt4 key购买 nike

我只是一个新手,我已经尽力找出如何解决我的问题,但我真的不明白。

我只想知道如何获取循环中当前行的主键/外键值。在我当前的代码中,我获得了最后一行的主键。我已尝试 $_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++;
}
?>

最佳答案

尝试在线PGSQL_BOTH,或者您可以将该参数留空,因为它是可选的

while ($r = pg_fetch_array($rs, NULL, PGSQL_BOTH)){

关于PHP 循环行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22302987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com