我正在尝试按布局和排序顺序对图像进行排序。我已经做到了,但不完全是我想要的样子。
<div id="sortableImages">
<ul>
<?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;
?>
<li class="sortPhotos" id="recordsArray_<?php echo $row['id']; ?>">
<img src="<?php echo $sortPath ?>" />
</li>
<?php } ?>
</ul>
</div>
这给了我一个输出
<ul class="ui-sortable">
<li class="sortPhotos" id="recordsArray_1392">
<img src="../data/gallery/208/images/album/front_cover.jpg" />
</li>
<li class="sortPhotos" id="recordsArray_1393">
<img src="../data/gallery/208/images/album/007.jpg" />
</li>
<li class="sortPhotos" id="recordsArray_1394">
<img src="../data/gallery/208/images/album/009.jpg" />
</li>
</ul>
我希望能够让它看起来像
<h2>Layout 1</h2>
<ul class="ui-sortable">
<li class="sortPhotos" id="recordsArray_1392">
<img src="../data/gallery/208/images/album/front_cover.jpg" />
</li>
</ul>
<h2>Layout 2</h2>
<ul>
<li class="sortPhotos" id="recordsArray_1393">
<img src="../data/gallery/208/images/album/007.jpg" />
</li>
<li class="sortPhotos" id="recordsArray_1394">
<img src="../data/gallery/208/images/album/009.jpg" />
</li>
</ul>
我需要一点帮助来弄清楚如何在 PHP 中正确嵌套循环。任何帮助将是一个很大的帮助。谢谢