我在while循环中有一个按钮,我想使用bootstrap样式。我实际上认为我可以替换当前的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>
";
}
答案 0 :(得分:2)
你需要逃避“放在回声中的那个。”
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>
";
}
答案 1 :(得分:0)
您可以使用变量添加所有文本然后打印。
$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;
}