gpt4 book ai didi

php - foreach循环重复值php sql

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:48 26 4
gpt4 key购买 nike

为什么这个双 foreach 循环会重复值

 foreach($_POST['studentpoints'] as $value) {
foreach($_POST['studentids'] as $valor) {
$stmt->bindParam(':studentid', $studentids);
$stmt->bindParam(':studentpoints', $points);
$studentids = $valor;
$points = $value;
$stmt->execute();
}

这段代码不重复值,只读取学生的第一个id

foreach($_POST['studentpoints'] as $value) { 
foreach($_POST['studentids'] as $valor) {
$studentids = $valor;
}

$stmt->bindParam(':studentid', $studentids);
$stmt->bindParam(':studentpoints', $points);
$studentids = $valor;
$points = $value;
$stmt->execute();

}

包含来自数据库的数据的表格

<?php foreach($rowstudents as $row): ?>
<tr>
<th><input type="hidden" name="studentids[]" value="<?php echo ' ' . htmlentities($row['studentid'], ENT_QUOTES, 'UTF-8') . ' ';?>" />
<?php echo '' . htmlentities($row['studentid'], ENT_QUOTES, 'UTF-8') . '';?></th>
<th><?php echo '' . htmlentities($row['fname'], ENT_QUOTES, 'UTF-8') . '';?></th>
<th><?php echo '' . htmlentities($row['lname'], ENT_QUOTES, 'UTF-8') . '';?></th>
<th><input type="text" name="studentpoints[]" value="<?php echo '' . htmlentities($row['studentpoints'], ENT_QUOTES, 'UTF-8') . '' ?>"></th>
</tr>
<?php endforeach; ?>
</table>

最佳答案

您正在使用 for each 循环两次。除此之外似乎没有任何问题

关于php - foreach循环重复值php sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23321236/

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