首页 > 解决方案 > 将行[“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

标签: 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 允许在属性周围使用任何一种类型的引号。


推荐阅读