Reputation: 4889
I tried storing data to php array from mysql using under code. But it's not working. This code:
echo $answerArray[count][i];
shows the correct result. But this code:
echo $answerArray[0][0];
doesn´t show anything.
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.
Upvotes: 3
Views: 217
Reputation: 12025
maybe this will work
$answerArray[$count][$i] = $row["num$j"];
(add $ before count and i)
Upvotes: 2