3 回答
TA贡献1831条经验 获得超9个赞
<?php
if ($stmt = $con->prepare(" SELECT p.*,i.img,title,id
from post AS p LEFT JOIN images AS i ON i.post_id= p.id ")) {
$stmt->execute();
}
$result = $stmt->get_result();
if ($result->num_rows>0) {
$firstTime=true;
while ($row = $result->fetch_assoc()) {
?>
<?php
if($firstTime==true){
echo $row['title'];
$firstTime=false;
}
?>
<img src="images/<?php echo $row['img']; ?>"height="20"width="20"/>
<?php
}}
?>
TA贡献1786条经验 获得超11个赞
列标题将重复等于图像表中返回的行数,您无法采取任何措施来阻止它。
如果您按标题分组,它将返回等于帖子表中行数的行数。
但如果你更详细地说明你真正想对结果做什么,我可能会帮助你。
TA贡献1827条经验 获得超9个赞
请尝试这个:-
<?php
$a1 = "";
$stmt = $con->prepare("SELECT p.*,i.img,title,id
from post AS p INNER JOIN images AS i ON i.post_id=p.id");
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows>0) {
while ($row = $result->fetch_assoc()) {
$title = $row['title'];
$img = $row['img'];
}
if($a1!= $title){
$activity="";
$activity.="<tr>
<td>$title</td>
</tr>;
}
$activity.="<tr>
<td><img src="images/<?php echo $img ?>"height="20"width="20"/></td>
</tr>";
$a1=$title;
}
?>
- 3 回答
- 0 关注
- 112 浏览
添加回答
举报