Data sorting PHP
<p>I am trying to sort my images by layout and sort order. I have kind of done it but not exactly how I want it to look. </p>

<pre><code>&lt;div id="sortableImages"&gt;
    &lt;ul&gt;
        &lt;?php
            $galleryID = $_SESSION['newGalleryId'];

            $query  = "SELECT * 
                        FROM galleryimage 
                        WHERE galleryId = $galleryID
                        ORDER BY sort 
                        AND layout
                        ASC";
            $result = mysql_query($query);

            while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $sortImageName = $row['OrgImageName']; 
                $sortPath = "../data/gallery/" . $_GET['edit'] . "/images/album/" . $sortImageName;
        ?&gt;
            &lt;li class="sortPhotos" id="recordsArray_&lt;?php echo $row['id']; ?&gt;"&gt;
                &lt;img src="&lt;?php echo $sortPath ?&gt;"  /&gt;                            
            &lt;/li&gt;
        &lt;?php } ?&gt;
    &lt;/ul&gt;
&lt;/div&gt;
</code></pre>

<p>This gives me an output of </p>

<pre><code>&lt;ul class="ui-sortable"&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1392"&gt;
                &lt;img src="../data/gallery/208/images/album/front_cover.jpg"  /&gt;                            
            &lt;/li&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1393"&gt;
                &lt;img src="../data/gallery/208/images/album/007.jpg"  /&gt;                            
            &lt;/li&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1394"&gt;
                &lt;img src="../data/gallery/208/images/album/009.jpg"  /&gt;                            
            &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>I would like to be able to get it to look like</p>

<pre><code>&lt;h2&gt;Layout 1&lt;/h2&gt;
&lt;ul class="ui-sortable"&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1392"&gt;
                &lt;img src="../data/gallery/208/images/album/front_cover.jpg"  /&gt;                            
            &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Layout 2&lt;/h2&gt;
&lt;ul&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1393"&gt;
                &lt;img src="../data/gallery/208/images/album/007.jpg"  /&gt;                            
            &lt;/li&gt;
                    &lt;li class="sortPhotos" id="recordsArray_1394"&gt;
                &lt;img src="../data/gallery/208/images/album/009.jpg"  /&gt;                            
            &lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>I need a little help figuring out how to nest the loops correctly in PHP. Any help would be a great help.
Thanks</p>
