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 關注
- 200 瀏覽
添加回答
舉報