3 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
<?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貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
列標(biāo)題將重復(fù)等于圖像表中返回的行數(shù),您無法采取任何措施來阻止它。
如果您按標(biāo)題分組,它將返回等于帖子表中行數(shù)的行數(shù)。
但如果你更詳細(xì)地說明你真正想對(duì)結(jié)果做什么,我可能會(huì)幫助你。

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
請(qǐng)嘗試這個(gè):-
<?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 關(guān)注
- 195 瀏覽
添加回答
舉報(bào)