[英]echo css classes in a while loop
我在while循環中有一個按鈕,我想在上面使用引導樣式。 我實際上以為我可以替換當前的HTML按鈕代碼,但出現錯誤: syntax error, unexpected 'form' (T_STRING), expecting ',' or ';'
。 有一種聰明的方式可以做到這一點嗎?
while($row = $res->fetch_assoc()) {
echo "Id: " . $row["id"]. "<br>" .
"<button>Read More</button><br><br>";
}
這是我想在我的while循環中設置的按鈕:
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-warning" >Send <span class="glyphicon glyphicon-send"></span></button>
</div>
</div>
我試圖在我的while循環中設置引導按鈕代碼,如下所示:
while($row = $res->fetch_assoc()) {
echo "Id: " . $row["id"]. "<br>" .
"
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-warning">Send <span class="glyphicon glyphicon-send"></span></button>
</div>
</div>
";
}
您需要轉義回顯中的“”。
while($row = $res->fetch_assoc()) {
echo "Id: " . $row["id"]. "<br>" .
"
<div class=\"form-group\">
<label class=\"col-md-4 control-label\"></label>
<div class=\"col-md-4\">
<button type=\"submit\" class=\"btn btn-warning\">Send <span class=\"glyphicon glyphicon-send\"></span></button>
</div>
</div>
";
}
您可以使用變量添加所有文本,然后打印。
$output = "";
while($row = $res->fetch_assoc()) {
$output = "Id: " . $row["id"] . "<br>";
$output .="<div class='form-group'>";
$output .="<label class='col-md-4 control-label'></label>";
$output .="<div class='col-md-4'>";
$output .="<button type='submit' class='btn btn-warning'>Send";
$output .="<span class='glyphicon glyphicon-send'></span></button>";
$output .="</div></div>";
echo $output;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.