Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中回显HTML时出错?_Php_Html - Fatal编程技术网

在PHP中回显HTML时出错?

在PHP中回显HTML时出错?,php,html,Php,Html,这个脚本出错了,我找不到它的位置,我知道它在$homeRandom部分,但我似乎不知道它是什么 有没有用PHP打印大量HTML的好方法 $sqla=“从产品中选择*”; $resulta=$conn->query($sqla); 如果($resulta->num_rows>0){ $homePage=''; 而($rowa=$resulta->fetch_assoc()){ $nav=''; $homeRandom “.$rowa[‘价格’]” “.$rowa['Description']”

这个脚本出错了,我找不到它的位置,我知道它在$homeRandom部分,但我似乎不知道它是什么

有没有用PHP打印大量HTML的好方法

$sqla=“从产品中选择*”;
$resulta=$conn->query($sqla);
如果($resulta->num_rows>0){
$homePage='';
而($rowa=$resulta->fetch_assoc()){
$nav='
  • '; $homeRandom “.$rowa[‘价格’]” “.$rowa['Description']”

    ' $homePage=$homePage.$homeRandom;
    }
    有没有一种用PHP打印大量HTML的好方法?

    是的,您可以使用打开和关闭php标记,并通过以下方法提高可读性:

    
    
    或者简单地使用正常的if语句:

    <?php if (condition) { ?>
    
    <!-- HTML goes here -->
    
    <?php } ?>
    
    
    
    或方法:


    echo您缺少一个分号,似乎缺少一个大括号,但这可能就是您复制和粘贴的方式

    $sqla = "SELECT * FROM Products";
        $resulta = $conn->query($sqla);
    
        if ($resulta->num_rows > 0) {
    
            $homePage = '';
    
            while($rowa = $resulta->fetch_assoc()) {
                $nav = '<li><a href="'.$rowa['UrlPage'].'">'.$rowa['Name'].'</a></li>';
                $homeRandom = '
                <div class="col-sm-4 col-lg-4 col-md-4">
                    <div class="thumbnail">
                        <img src="./content/images/homepage/'.$rowa['ImageName'].'.jpg" alt="">
                        <div class="caption">
                            <h4 class="pull-right">'.$rowa['Price'].'</h4>
                            <h4><a href="'.$rowa['UrlPage'].'">'.$rowa['Name'].'</a>
                            </h4>
                            <p>'.$rowa['Description'].'</p>
                        </div>
                    </div>
                </div>'; //<-- missing in yours
    
                $homePage = $homePage . $homeRandom; 
            }
    } //<-- also missing in yours, but could just be a copy 
      //paste missed the last }
    
    $sqla=“从产品中选择*”;
    $resulta=$conn->query($sqla);
    如果($resulta->num_rows>0){
    $homePage='';
    而($rowa=$resulta->fetch_assoc()){
    $nav='
  • '; $homeRandom “.$rowa[‘价格’]” “.$rowa['Description']”


    “;//你有什么错误?除了遗漏的分号以外?@johncode如果我将$homePage=$homePage.$homeRandom;切换到$nav=$homePage.$homeRandom;那么我知道是$homeRandom部分。@IgnacioVazquez Abrams天哪,我真的很累了…非常感谢!”;$homePage=$homeRandom;你忘记了一个sem我是冒号,在div之后
    echo <<<EOT
    <p>My name is "$name". I am printing some $foo->foo.</p>
    <p>Now, I am printing some {$foo->bar[1]}.</p>
    <p>This should print a capital 'A': \x41</p>
    EOT;
    
    $sqla = "SELECT * FROM Products";
        $resulta = $conn->query($sqla);
    
        if ($resulta->num_rows > 0) {
    
            $homePage = '';
    
            while($rowa = $resulta->fetch_assoc()) {
                $nav = '<li><a href="'.$rowa['UrlPage'].'">'.$rowa['Name'].'</a></li>';
                $homeRandom = '
                <div class="col-sm-4 col-lg-4 col-md-4">
                    <div class="thumbnail">
                        <img src="./content/images/homepage/'.$rowa['ImageName'].'.jpg" alt="">
                        <div class="caption">
                            <h4 class="pull-right">'.$rowa['Price'].'</h4>
                            <h4><a href="'.$rowa['UrlPage'].'">'.$rowa['Name'].'</a>
                            </h4>
                            <p>'.$rowa['Description'].'</p>
                        </div>
                    </div>
                </div>'; //<-- missing in yours
    
                $homePage = $homePage . $homeRandom; 
            }
    } //<-- also missing in yours, but could just be a copy 
      //paste missed the last }