我正在尝试制作像Facebook或Instagram这样的故事系统。正如您在下表中看到的那样s_id
是唯一的帖子ID和uid_fk
帖子创建的用户ID。
uid_fk
=> 4 在此表中创建 3 帖子。
和
uid_fk
=> 5 也创建 3 帖子。
如果查询是:
$query = mysqli_query($this->db,"SELECT s_id, uid_fk, stories_img FROM stories_posts") or die(mysqli_error($this->db));
然后html输出看起来像这样
<!--
id=s_id ,
data_uidfk=uid_fk ,
div inside imgage stories_img
-->
<div class="post" id="1" data_uidfk="4">15019557244.jpg</div>
<div class="post" id="2" data_uidfk="5">150021986050.png</div>
<div class="post" id="3" data_uidfk="4">14939786704.gif</div>
<div class="post" id="4" data_uidfk="5">14939786777.jpg</div>
<!--And other posts-->
我的问题是如何将数据集显示为单个帖子 ,
<!--
id=s_id ,
data_uidfk=uid_fk ,
div inside imgage stories_img
-->
<div class="post" data_uidfk="4">
All uid_fk = 4 posts will be show in this div.
</div>
<div class="post" data_uidfk="5">
All uid_fk = 5 posts will be show in this div.
</div>
<!--And other posts-->
提前感谢您的帮助。
答案 0 :(得分:1)
您可以将查询更改为:
<div> Name: <%= suplement.name %></div>
<div> Number of units: <%= suplement.number_of_units %></div>
<div>Daily dosage in units: <%= suplement.daily_dosage_in_units %></div>
<div>Number of days: <%= suplement.number_of_days %></div>
<div>Supplement cost: <%= suplement.suplement_cost %></div>
<div>Total cost: <%= suplement.total_cost %></div>
记录将返回:
SELECT uid_fk, group_concat(stories_img) as pics
FROM stories_posts
GROUP BY uid_fk
然后展开以设置单个图像并将它们放在必要的html元素中。