gpt4 book ai didi

php - 通知 : Undefined offset: 3 php sql

转载 作者:太空宇宙 更新时间:2023-11-03 12:13:17 24 4
gpt4 key购买 nike

这里显示的数据来自两个表:

第一列有fname,

第二列包含总和

这段代码创建了一个如下所示的表格:

+---------------------+
| First Name | Total |
+---------------------+
| Pedro | 19 |
| Carlos | 10 |
| Albert | (NULL) |
+---------------------+

因为 Albert 对 Total 没有任何值(value),所以我得到了这个:

Notice: Undefined offset: 3

谁能给我解释一下这是什么,如果可以解决

<?php foreach($rowstudent as $k=>$rowst): ?>
<tr>
<th><?php echo '' . htmlentities($rowst['fname'], ENT_QUOTES, 'UTF-8') . '';?></th>

<th> <?php echo ' ' . htmlentities($rowstudentpoints[$k]['sum'], ENT_QUOTES, 'UTF-8') . '<br>';?></th>
</tr>
<?php endforeach; ?>

最佳答案

这是对您的错误的快速修复:

<?php foreach($rowstudent as $k=>$rowst): ?>
<tr>
<th><?php echo '' . htmlentities($rowst['fname'], ENT_QUOTES, 'UTF-8') . '';?></th>

<th> <?php echo ' ' . htmlentities(isset($rowstudentpoints[$k]['sum'])?$rowstudentpoints[$k]['sum']:'', ENT_QUOTES, 'UTF-8') . '<br>';?></th>

</tr>
<?php endforeach; ?>

关于php - 通知 : Undefined offset: 3 php sql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23335131/

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