我的 MYSQL 表“用户”中共有 8 个结果/用户。
我想每行显示 6 个结果/用户配置文件图像,如下所示:
1st Result. 2nd Result. 3rd Result. 4th Result. 5th Result. 6th Result
7th Result. 8th Result. No More Results.....
要求每行至少包含 6 个结果/个人资料图片。如果没有足够的结果/个人资料图片来完成一行,那么我会尝试使用模板个人资料图片“在此处宣传您的个人资料”来填充空间。
advertise here 模板图像存储在以下目录中:
<div><img src="data/profile/0/main/advert.jpg" alt="Profile" height="100%" width="100%"></div>';
给出期望的结果:
1st Result. 2nd Result. 3rd Result. 4th Result. 5th Result. 6th Result
7th Result. 8th Result. 9 Ad Here. 10 Ad Here. 11 Ad Here. 12 Ad Here.
这是我目前拥有的代码,感谢用户@MegaColorBoy 到目前为止帮助我编写代码。
但是,代码仍然没有给出预期的结果。请有人帮助改进修改代码,让它给我我需要的结果。谢谢。
代码:
<?php $sql = "SELECT * FROM users WHERE status = 'active' AND usertype = 'advertiser'";
$result = $conn->query($sql)->fetch_all(MYSQLI_ASSOC);
$limit = 6;
$chunks = array_chunk($result, $limit);
foreach($chunks as $chunk){
echo '<div id="category_case_holder">';
foreach($chunk as $chunkItem){
echo '<div id="prime"><a href="profile.php?id='.htmlspecialchars($chunkItem['user_id']).'"><img src="data/profile/'.htmlspecialchars($chunkItem['user_id']).'/main/profile.jpg" alt="Profile" height="100%" width="100%"></a></div>';
}
echo '</div>';
} ?>
摇曳的蔷薇
芜湖不芜
繁星coding