I've got 2 tables one holds questions and one holds answers. I was wondering if I can grab and echo them through a function. So basically loop through the questions and echo question + answers.
Questions
+------+-------------------------------+
| q_id | question |
+------+-------------------------------+
| 1 | What is your favorite color? |
+------+-------------------------------+
Answers
+------+------+-----------+
| a_id | q_id | answer |
+------+------+-----------+
| 1 | 1 | Green |
+------+------+-----------+
| 2 | 1 | Blue |
+------+------+-----------+
| 3 | 1 | Yellow |
+------+------+-----------+
What I have done until now
function Questionaire()
{
if(!$this->DBLogin())
{
$this->HandleError("Database login failed!");
return false;
}
$result = array();
$conn = $this->connection;
$query = "SELECT * FROM `questions` WHERE status = 1";
$result = $conn->query($query);
while ($row = $result->fetch()) {
$result[] = $row['question'];
}
return $result;
}