foreach は各ヘッダーを出力し、すべてのアコーディオンを取得しますが、最初のアコーディオン以外はすべて空です。私は何が欠けていますか?
$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>';
}