php - 在 while 循环中回显 css 类

标签 php html css

我在 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>
                 ";
}

最佳答案

您需要转义放在 echo 中的 "。

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>
                 ";
}

关于php - 在 while 循环中回显 css 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43478203/

相关文章:

html - iframe 中的内容会重定向,但不会重定向整个页面

jquery - 修复了平板电脑和手机问题的导航栏

css - 横幅图片在移动设备上没有响应

php - 关于php中的框架

javascript - 如何在 PHP 的字符串 echo 中使用 window.open ?

PHP Composer 自动加载需要永远

c++ - Qt 中的字体编辑器小部件

php - Mcrypt 扩展的 Codeigniter 临时解决方案

java - Jsoup 在指定标签后开始解析还是从页面底部开始?

html - 如何在网站上嵌入带聊天功能的 twitch.tv channel ?