Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP注意:未定义偏移量381和382,带有in-while循环_Php_Mysql - Fatal编程技术网

PHP注意:未定义偏移量381和382,带有in-while循环

PHP注意:未定义偏移量381和382,带有in-while循环,php,mysql,Php,Mysql,这段代码显示了一个错误,如PHP注意事项:未定义的偏移量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

这段代码显示了一个错误,如PHP注意事项:未定义的偏移量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++;
    }
}
将代码更改为:

$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++;
    }
}

谢谢你的帮助。我已经解决了它。问题是$row['qid']和[1]$行['qid']是一个整数,但我使用$row['qid']的键是varchar类型的键,类似于q381,我只使用了381。所以我把$row['qid']改成了q.$row['qid'],它就工作了。
1的另一个问题是,该键也在更改,因此我将其替换为相应的变量,它工作正常

感谢您的帮助。我已经解决了它。问题是$row['qid']和[1]$行['qid']是一个整数,但我使用$row['qid']的键是varchar类型的键,类似于q381,我只使用了381。所以我把$row['qid']改成了q.$row['qid'],它就工作了。
1的另一个问题是该键也在更改,因此我将其替换为相应的变量,并且它工作正常

$json['responses'][0][1]['381']
不存在。如果存在isset,请首先检查它
if(isset($json['responses'][0][1][$row['qid']])和&$row['a_sortorder..
我找到了解决方案。在$json['responses'][0][1][$row['qid']]中,$row['qid']应该是q.$row['qid']..第三方应用程序更改了qid,并将q与qid关联起来。
$json['responses']0][1]['381']
不存在。请先检查isset是否存在。
如果(isset($json['responses'][0][1][$row['qid']])和&$row['a_sortorder…
我找到了解决方案。在$json['responses'][0][1][$row['qid']]中,$row['qid']应该是q.$row['qid']…qid被第三方应用程序更改,它包含q和qid。你认为这对除你之外的其他人有帮助吗?这可能有帮助…如果有人犯类似错误,可以将其用作参考…我不知道未定义的偏移量x,其中x可以是任何值,之前我对它有一些了解,但现在我对不知道未定义的偏移量它可能有帮助你认为这对除你之外的其他人有帮助吗?它可能有帮助…如果有人犯了类似的错误,可以使用它作为参考…我不知道未定义的偏移量x,其中x可以是任何值,早些时候,但现在我有一些想法,所以对于不知道未定义偏移量的人,我也许有帮助