php - 将行[“tddaw”]放在逗号中
问题描述
所以我想知道我怎么能把
<?php
$sql = "SELECT title, script_desc, banner, author, price FROM market";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo " <div class=\"item col-xs-4 col-lg-4\">
<div class=\"thumbnail\">
<img class=\"group list-group-image\" src=\"http://placehold.it/400x250/000/fff\" alt=\"\" />" . $row["banner"] . "/> <div class=\"caption\">
<h4 class=\"group inner list-group-item-heading\">" . $row["title"] . "</h4><div class=\"row\">
<div class=\"col-xs-12\">
<div class=\"col-xs-12 col-md-3\">
<p class=\"lead\">"
. $row["price"] . "</div>
<div class=\"col-xs-12 col-md-5\">
0 reviews<br>
<span class=\"glyphicon glyphicon-star\"></span>
<span class=\"glyphicon glyphicon-star\"></span>
<span class=\"glyphicon glyphicon-star\"></span>
<span class=\"glyphicon glyphicon-star\"></span>
<span class=\"glyphicon glyphicon-star\"></span>
</div>
<div class=\"col-xs-12 col-md-4\">
<a class=\"btn btn-success\" href=\"scripts/example1\">" . $row["title"] . "</a> </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
";
$conn->close();
?>
echo " <div class=\"item col-xs-4 col-lg-4\">
<div class=\"thumbnail\">
<img class=\"group list-group-image\" src=\"http://placehold.it/400x250/000/fff\" alt=\"\" />" . $row["banner"] . "/>
所以将来源更改"src=\"http://placehold.it/400x250/000/fff\" "
为" src=\"$row["banner"] "
所以把$row["Banner"]
而不是"src=\"http://placehold.it/400x250/000/fff\"
所以基本上把行放在逗号里面很抱歉听起来很笨拙,不久前才开始使用php
解决方案
更改此行:
<img class=\"group list-group-image\" src=\"http://placehold.it/400x250/000/fff\" alt=\"\" />" . $row["banner"] . "/> <div class=\"caption\">
至
<img class=\"group list-group-image\" src=\"" . $row["banner"] . "\" alt=\"\" />" . $row["banner"] . "/> <div class=\"caption\">
这与您将所有其他$row
变量嵌入到输出中的方式相同。
顺便说一句,如果您在字符串周围使用单引号,则不必转义里面的所有双引号。或者您可以在内部使用单引号,因为 HTML 允许在属性周围使用任何一种类型的引号。
推荐阅读
- c# - C#/CLI 包装器“无法加载文件或程序集”
- python - 用 Beautiful Soup 和 Selenium 一起刮时出错
- node.js - 正则表达式替换文本数组中的主题标签
- angularjs - 在主干和 Angularjs 的情况下,Highcharts 默认比例间隔不同
- javascript - flexbox list column-reverse 并从顶部开始
- nginx - 使用 nginx 入口控制器为金丝雀版本启用会话亲和性
- reactjs - 除了我不想在 redux-persist 中清除的内容之外,如何清除所有内容?
- scala - 任务不可序列化:java.io.NotSerializableException:org.apache.spark.unsafe.types.UTF8String$IntWrapper
- java - Tomcat 在不同机器上部署时找不到 servlet 和 JSP 文件
- ruby - 字符串包括来自数组的子字符串