<分区>
我可能遗漏了一些明显的东西,我怎样才能返回我需要的结果?看看这个简单的例子:
$fetch_image = "SELECT image_url FROM table"; //returns about 10 rows
$stmt_img = $db->prepare($fetch_image);
$stmt_img->execute();
$stmt_img_result = $stmt_img->get_result();
while ($row_img = $stmt_img_result->fetch_assoc()) {
$image = $row_image['image_url'];
echo 'Image url: '.$image.'<br>'; //this will echo out 10 times.
}
以上代码遍历所有 10 行。如何返回结果集中的第一行,然后返回其他 9 行?
编辑:我正在尝试创建一个图像预览器,以便第一张图像显示为占位符/主图像,然后其他 9 行显示为缩略图,如下所示:
<div class="sp-wrap">
<a href="images/1.jpg">
<!-- This would be the placeholder/main/first image from the mysql result set -->
<img src="images/1_tb.jpg" alt="">
</a>
<!-- In real life these would be dynamically generated -->
<a href="images/3.jpg"><img src="images/3_tb.jpg" alt=""></a>
<a href="images/4.jpg"><img src="images/4_tb.jpg" alt=""></a>
<a href="images/5.jpg"><img src="images/5_tb.jpg" alt=""></a>
<a href="images/6.jpg"><img src="images/6_tb.jpg" alt=""></a>
</div>