Hi everybody,
I'm wondering where I went wrong. The idea is I'm trying to get data from the database and display in this format
Question 1:
Answer:
Answer:
Answer:
Answer:
Question 2:
Answer:
Question 3:
No answers
etc..
foreach($posts as $post){
$id = (int)$post['id'];
$comments = get_comments($id);
//getting the answers
foreach($comments as $comment){
echo "<h1>" .$post['title'] ." id:" .$post['id'] ."</h1>";
echo $post['body'] ."<br/>";
echo " <small>Asked at " .$post['date_published'] ."</small>";
echo "<br/>";
echo "<br/>";
echo "<strong> <div>";
echo $comment['body'] ."<br/>";
echo "Answered by " .$comment['answered_by'] ."</br>";
echo "<small>" .$comment['date_published'] ."</small>";
echo "</div> </strong>";
}
}
Thank you so much in advance. It would be good to give a brief explanation with examples of how Nested foreach loops work.