[英]How insert a new line for each result of query select
我檢查了所有類似的問題,但沒有找到答案。
我想在查詢選擇的每個結果之后插入一個<br/>
但我不能這樣做,也許是因為我在 CSS 中使用了float
屬性。
我將用代碼解釋我的問題:
$sqlUser = "SELECT id,username FROM utenti where id IN (select idUtente from motopartecipanti where idItinerario = '".$idViaggio."') ORDER BY username";
$resultUser = $mysqli->query($sqlUser);
while($rowUser = $resultUser->fetch_assoc()) {
$username = $rowUser["username"];
$idUtente = $rowUser["id"];
echo '
<div style="float:left;">
<label>'.$username.'</label>
</div>
';
$sqlTipo = "SELECT tipo FROM moto where id IN (select idMoto from
motopartecipanti where idItinerario = '".$idViaggio."' AND idUtente =
'".$idUtente."') ";
$resultTipo = $mysqli->query($sqlTipo);
while($rowTipo = $resultTipo->fetch_assoc()) {
$tipo = $rowTipo["tipo"];
echo '
<div style="float:right;">
<label>'.$tipo.'</label>
</div>
';
}
}
該代碼有效,但輸出為:
Username1Username2 Type1Type2
相反,它應該是:
Username1 Type1
Username2 Type2
我也使用了mysql
標簽,因為它可能是查詢語法的問題
您可以回顯<br/>
標簽,或者我認為如果您回顯一行而不是`
. 但是,這取決於您的要求。
echo '
<div style="float:right;">
<label>'.$tipo.'</label> <br/>
</div>
';
在 $tipo 'div' 標簽的末尾添加一個 '' 標簽
while($rowTipo = $resultTipo->fetch_assoc()) {
$tipo = $rowTipo["tipo"];
echo '
<div style="float:right;">
<label>'.$tipo.'</label>
</div><div style="clear:both">
';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.