PHP 通知 : undefined offset 381 and 382 with in while loop

标签 php mysql

此代码显示类似 PHP Notice 的错误: undefined offset 381。 并且偏移量随着循环运行而增加。

$marks=0;
$correct = 0;
while ($row=mysqli_fetch_assoc($result)){
    $exam_name = $row['exam_name'];
    $exam_percentage = $row['exam_pass_percentage'];
    if($row['a_sortorder'] == $json['responses'][0][1][$row['qid']]){
        $marks = $marks + 4;
        $correct++;
    }
}

不知道该怎么办?

最佳答案

将您的代码更改为:

$marks=0;
$correct = 0;
while ($row=mysqli_fetch_assoc($result)){
    $exam_name = $row['exam_name'];
    $exam_percentage = $row['exam_pass_percentage'];
    if(isset($row['a_sortorder']) && isset($json['responses'][0][1][$row['qid']]) && $row['a_sortorder'] == $json['responses'][0][1][$row['qid']]){
        $marks = $marks + 4;
        $correct++;
    }
}

关于PHP 通知 : undefined offset 381 and 382 with in while loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458450/

相关文章:

java - 向服务器发送 GPS 数据不起作用?

MySQL:我有一些主键问题

php - 从数据库中的交集行和列中选择一个价格

php - 插入两个不同的表

php - Codeigniter 多个 where 条件

php - session 重新生成导致具有快速 AJAX 调用的 session 过期

php - CakePHP,保存和访问逗号分隔的 MySQL 列以进行 "group"标识

java - Spring Boot + MySQL 社区服务器

mysql - 为什么查询没有 LIMIT 子句返回空结果集?

php - 数据库-字符串作为主键?