du94414 2011-10-09 07:20
浏览 39
已采纳

如何将MySQL的结果存储到PHP数组?

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.
  • 写回答

2条回答 默认 最新

  • dongxingchang9345 2011-10-09 07:24
    关注

    maybe this will work

     $answerArray[$count][$i] = $row["num$j"];
    

    (add $ before count and i)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?