Hi All,
I am new to MD arrays and especially when trying to get the data in an orderly fashion from a DB with this.
Here is what the data looks like in my db...
question_id -------- answer
1 ------------------ Because a pencil is cheap
1 ------------------ Because everyone uses a pencil
2 ------------------ Mining
2 ------------------ Logging
etc.
I need to retrieve the data into an array for my function as such...
$answer = array();
$answer[1] = array("A" => "Because a pencil is cheap", "B" => "Because everyone uses a pencil");
$answer[2] = array("A" => "Mining", "B" => "Logging");
but I am not even getting close trying to combine it like this example I found...
$query="SELECT question_id, answer FROM answers WHERE quiz_id='1'";
$result = mysql_query($query) or die(mysql_error());
foreach ($array as $key => $value)
{
echo '<b>top level:</b> ' . $key . '<br>';
foreach ($value as $subkey => $subvalue)
{
echo $subkey . ') '.$subvalue .'<br />';
}
}
Can someone give me some guidance?
I appreciate the help in advance,
Don