For the past month, I have trying to create a database that stores English and Japanese words. I then wanted to use the data populated by myself to quiz me on my progress. I have been working on this script to get it to pull random questions and display in a multiple choice format. I have getting this error as I am trying to create a new array which will hold 4 questions.
[php]
function WrongAnswer(){
static $counter;
$counter =0;
$username = “saori”;
$password = “”;
$hostname = “Jamal-pc”;
$conn = new PDO(‘mysql:host=Jamal-PC;dbname=japanesewords’,$username,$password);
$sql =‘Select EnglishWord from japanesedefinition;’;
$stmt = $conn->prepare($sql);
$stmt ->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
print_r($result);
$sizeofArray = sizeof($result);
//make this while loop store this into a new array
//also be sure to add the answer after the loop enters
//then shuffle the array
//the methods will call this function and give out the questions
$storeanswer = array ();
if($counter==0){
for($x=0;$x<3;$x++){
$storeanswer = rand(0,$sizeofArray);
$answer = $result[$storeanswer]->EnglishWord;
$storeanswer[$x]=$answer;
}
$counter++;
}
}
}
[/php]
I did a var_dump and the $answer is a string, so why can’t I just add them into a new array. I wanted the array to hold my random questions.
Am I missing something basic here?
Thanks in advance.