Q:

While Loop Only Works On First Run

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>';
    }

A:

Without your schema I can't be sure, but it looks like faq is related to section by sectionname. If that's true, something like this:
foreach ($sectionnames as $sectionname) {
        echo '<h3 id="sectionname">' . $sectionname . '</h3>';
        echo '<div id="accordion">';
        $result = mysqli_query($con,"SELECT * FROM faq where section = '$sectionname' ORDER BY `order`");
        while($row = mysqli_fetch_array($result)) {   
           echo '<h3>' . $row['heading'] . '</h3>';
           echo '<div>' . $row['content'] . '</div>';    
       }
       echo '</div>';
}

