Expected Result: I have several echo statements and I should be getting something like this:
index1
Question->addChoice1
Choice1
Choice2
Question->addChoice2
index2
Actual Results:
index1
Question->addChoice1
Choice1
Choice2
Its failing at:
$this.$choices[] = new Choice($obj);
I have no idea why its doing this, but its almost 3AM here so maybe I'm just too brain-dead to see it. please help.
index.php
$QUESTIONS = array();
for ($chapter=1; $chapter<=count($max_chapter); $chapter++) {
$question_qry = "SELECT * FROM $tbl_questions WHERE chapter=$chapter ORDER BY RAND() LIMIT $max_chapter[$chapter]";
$question_req = mysql_query($question_qry);
while ($question_obj = mysql_fetch_object($question_req)) {
$newQuestion = new Question($question_obj);
$choice_qry = "SELECT * FROM $tbl_choices WHERE question=$question_obj->reference ORDER BY choice ASC;";
$choice_req = mysql_query($choice_qry);
while ($choice_obj = mysql_fetch_object($choice_req)) {
echo "index1<br>";
$newQuestion->addChoice($choice_obj);
echo "index2<br>";
}
$QUESTIONS[] = $newQuestion;
echo '<pre>'; print_r($newQuestion); echo '</pre>';
}
}
shuffle($QUESTIONS);
echo '<pre>'; print_r($QUESTIONS); echo '</pre>';
question.php
class Question {
private $chapter;
private $topic;
private $reference;
private $question_name;
private $question_correct;
private $special;
private $pic;
private $choices = array();
function __construct($obj) {
$this->chapter = $obj->chapter;
$this->topic = $obj->topic;
$this->reference = $obj->reference;
$this->question_name = $obj->question_name;
$this->question_correct = $obj->question_correct;
$this->special = $obj->special;
$this->pic = $obj->pic;
}
public function addChoice($obj){
echo "Question->addChoice1<br>";
$this.$choices[] = new Choice($obj);
echo "Question->addChoice2<br>";
}
...
choice.php
class Choice {
private $chapter;
private $question;
private $choice;
private $choice_name;
private $choice_explanation;
function __construct($obj) {
echo "Choice1<br>";
$this->chapter = $obj->chapter;
$this->question = $obj->question;
$this->choice = $obj->choice;
$this->choice_name = $obj->choice_name;
$this->choice_explanation = $obj->choice_explanation;
echo "Choice2<br>";
}
...
$this->choices[] = new Choice($obj);instead of$this.$choices[] = new Choice($obj);