The foreach prints out each of the headers, and I get all the accordions, but everything but the first accordion are empty. What am I missing?
$result2 = mysqli_query($con, "SELECT * FROM sections ORDER BY `order`");
$sectionnames = array();
while($row = mysqli_fetch_array($result2)) {
$sectionnames[] = $row['sectionname'];
}
$result = mysqli_query($con,"SELECT * FROM faq ORDER BY `order`");
foreach ($sectionnames as $sectionname) {
echo '<h3 id="sectionname">' . $sectionname . '</h3>';
echo '<div id="accordion">';
while($row = mysqli_fetch_array($result)) {
if ($sectionname == $row['section']) {
echo '<h3>' . $row['heading'] . '</h3>';
echo '<div>' . $row['content'] . '</div>';
}
}
echo '</div>';
}