OK I made some changes:
DatabaseName: quiz
Tables: answers(id, answer_id, answer_text)
questions(question_id, question_text)
Values:
answers:
id(primary key, int, not null, auto-increment, unsigned)
answer_id(int, not null) - this field links to question_id from questions table
answer_text(varchar, not null)
[B]questions:[/B]
question_id(primary key, int, not null, auto-increment, unsigned)
question_text(varchar, not null)
Query Code: Here I want to create arrays containing the info from database. The info in the answers table should be linked to info from questions table
// Perform Query
mysql_select_db('quiz') or die('Could not select Database');
$result = mysql_query('SELECT * FROM questions');
while ($row = mysql_fetch_assoc($result))
{
$questions[$row['question_id']] = $row['question_text'];
}
$result = mysql_query('SELECT * FROM answers');
while ($row = mysql_fetch_assoc($result))
{
$answers[$row['question_id']][$row['answer_id']] = $row['answer_text'];
}
Finally the Output/Loop code:
echo '<form action="" method="POST">';
foreach ($answers as $key => $value)
{
echo $key . '. ' . $questions[$key] . '<br>';
foreach ($value as $answer_key => $answer_value)
{
echo '<input type="radio" name="answers[' . $key . ']" value="' . $answer_key . '"> ' . $answer_value . '<br>';
}
echo '<br>';
}
echo '<input type="submit" name="submit" value="submit">
</form>';
I really appreciate any help. I've been working at this for the past few days but still unable to get the sesired results.
Thanks.
Kevin