I tried storing data to php array from mysql using under code. But it's not working. This code:
我尝试在代码中使用mysql将数据存储到php数组中。但这不是工作。这段代码:
echo $answerArray[count][i];
shows the correct result. But this code:
显示正确的结果。但这段代码:
echo $answerArray[0][0];
doesn´t show anything.
并´t展示什么。
What should I do to fix it? Thank you.
我该怎么做才能修好它?谢谢你!
Full code:
完整的代码:
$count = 0; //answer count
$answerArray = array();
while ($row = mysqli_fetch_array($resultFromR, MYSQLI_ASSOC)) { //add array from db
for($i = 0; $i < $questionNumber; $i++) {
$j = $i + 1;
$answerArray[count][i] = $row["num$j"];
echo $answerArray[count][i]; //is working.
}
$count++;
}
echo '<br />';
echo $answerArray[0][0]; //something wrong!!! I cannot get anything from this.
2 个解决方案
#1
2
maybe this will work
也许这将工作
$answerArray[$count][$i] = $row["num$j"];
(add $ before count and i)
(在计数和i之前增加$)
#2
1
Not sure but shouldn't the [i] be [$i]?
不确定,但[i]不应该是[$i]吗?
#1
2
maybe this will work
也许这将工作
$answerArray[$count][$i] = $row["num$j"];
(add $ before count and i)
(在计数和i之前增加$)
#2
1
Not sure but shouldn't the [i] be [$i]?
不确定,但[i]不应该是[$i]吗?