Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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 div冲突_Php_Html - Fatal编程技术网

Php 输出html div冲突

Php 输出html div冲突,php,html,Php,Html,我在处理html输出时遇到了最奇怪的情况。如果查看//开始库行,第一个输出工作正常,这是我的问题开始的地方 这就是输出的外观 <div class='row'> <div class='col-md-12'> <div id='gallery-slider' class='slider responsive'> <img class='img-responsive' src='cdn/assets/gall

我在处理html输出时遇到了最奇怪的情况。如果查看//开始库行,第一个输出工作正常,这是我的问题开始的地方

这就是输出的外观

<div class='row'>
    <div class='col-md-12'>
        <div id='gallery-slider' class='slider responsive'>
            <img class='img-responsive' src='cdn/assets/gallery/1.jpg'>
            <img class='img-responsive' src='cdn/assets/gallery/3.jpg'>
            <img class='img-responsive' src='cdn/assets/gallery/2.jpg'>
            <img class='img-responsive' src='cdn/assets/gallery/4.jpg'>
            <img class='img-responsive' src='cdn/assets/gallery/5.jpg'>
        </div>
    </div>
</div>

好的,所以我认为最好的方法是循环使用$result,过滤掉所有重复的值,并将图像分配给一个以行['ID']为键的数组,然后在检查后循环使用它们

$checker = array();
$profileArray = array();
while ($row = mysqli_fetch_assoc($result))
{
    if($row['GalleryImage'])
    {
        $profileArray[$row['ID']]['GalleryImages'][] = $row['GalleryImage'];
    }

    if(!in_array($row['ID'], $checker))
    {
        while (list ($key, $value) = each($row))
        {
            if($key != 'GalleryImage')
            {
                $profileArray[$row['ID']][$key] = $value;
            }
        }
        $checker[] = $row['ID'];
    }
}

foreach ($profileArray as $row)
{
    $ID = $row['ID'];
    $FullName = $row['FullName'];
    $Email = $row['Email'];
    $JobTitle = $row['JobTitle'];
    $Bio = $row['Bio'];
    $Photo = $row['Photo'];
    $GalleyImages = $row['GalleryImages'];

    if (isset($Photo) && !empty($Photo))
    {
        $ProfileImage = "$Photo";
    }
    else
    {
        $ProfileImage = "avatar.jpg";
    }

    $output .= "
    <div class='container yep team-wrap'>
      <div class='row'>        
        <div class='col-md-6'>
            <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
        </div>
    <div class='col-md-6'>
      <strong>$FullName<br>$JobTitle</strong>
         <br>
        <p>$Bio</p>
       <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
    </div> 
</div>";

    //End of info row
    $output .= "<br /><br /><br />";

    //Start Gallery Row
    $output .= "
        <div class='row'>
         <div class='col-md-12'>
        <div id='gallery-slider' class='slider responsive'>";

    if(!$GalleyImages)
    {
        foreach ($GalleyImages as $img)
        {
            //Display this row as many times as needed by data in this row.
            $output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
        }
    }
    else
    {
        $output .= "HTML THAT YOU WANNA DISPLAY instead of images";
    }

    $output .= "
                </div>
            </div>
        </div>
    </div>";
}
echo $output;
$checker=array();
$profileArray=array();
while($row=mysqli\u fetch\u assoc($result))
{
如果($row['GalleryImage']))
{
$profileArray[$row['ID']['GalleryImage'][]=$row['GalleryImage'];
}
if(!in_数组($row['ID'],$checker))
{
while(列表($key,$value)=每个($row))
{
如果($key!=“GalleryImage”)
{
$profileArray[$row['ID'][$key]=$value;
}
}
$checker[]=$row['ID'];
}
}
foreach($profileArray作为$row)
{
$ID=$row['ID'];
$FullName=$row['FullName'];
$Email=$row['Email'];
$JobTitle=$row['JobTitle'];
$Bio=$row['Bio'];
$Photo=$row['Photo'];
$GalleryImages=$row['GalleryImages'];
如果(设置($Photo)&!空($Photo))
{
$ProfileImage=“$Photo”;
}
其他的
{
$ProfileImage=“avatar.jpg”;
}
$output.=”
$FullName
$JobTitle

$Bio

"; //信息行末尾 $output.=“


”; //开始画廊行 $output.=” "; 如果(!$GalleyImages) { foreach($GalleyImages作为$img) { //按此行中的数据所需的次数显示此行。 $output.=“”; } } 其他的 { $output.=“要显示而不是图像的HTML”; } $output.=” "; } echo$输出;
好的,首先,正确格式化代码总是好的,这样你就不会犯这些错误

您的第一个输出缺少结束div

<div class='container yep team-wrap'>
    <div class='row'>        
        <div class='col-md-6'>
            <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
        </div>

        <div class='col-md-6'>
            <strong>$FullName<br>$JobTitle</strong>
            <br>
            <p>$Bio</p>
            <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
        </div> 
    </div>
</div> <!-- This was missing-->

$FullName
$JobTitle

$Bio

最后,您必须关闭if语句以快速绕过以下代码:

//Start Gallery Row
    $output .= "
        <div class='row'>
         <div class='col-md-12'>
        <div id='gallery-slider' class='slider responsive'>
       ";
} // CLOSED AT THE WRONG SPOT
//启动库行
$output.=”
";
}//在错误的位置关闭
请尝试以下方法:

<?php
    $stmt = $db->prepare("my query");
    $stmt->execute();
    $result = $stmt->get_result();

    $output = "";
    $checker = [];

    while ($row = mysqli_fetch_assoc($result)) {
        $ID = $row['ID'];        
        $FullName = $row['FullName'];    
        $Email = $row['Email'];   
        $JobTitle = $row['JobTitle'];
        $Bio = $row['Bio'];
        $Photo = $row['Photo'];  


        $GalleryImage = explode(',', $row['GalleryImage']);


        if (isset($Photo) && ! empty($Photo)) {
            $ProfileImage = "$Photo";
        } else {
            $ProfileImage= "avatar.jpg";
        }       


        if(!in_array($row['ID'], $checker)) {

            $output .= "
                <div class='container yep team-wrap'>
                    <div class='row'>        
                        <div class='col-md-6'>
                            <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
                        </div>

                        <div class='col-md-6'>
                            <strong>$FullName<br>$JobTitle</strong>
                            <br>
                            <p>$Bio</p>
                            <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
                        </div> 
                    </div>
                </div> <!-- This was missing-->
            ";

           //End of info row


            $output .="<br /><br /><br />";


           //Start Gallery Row

           $output .= "
                <div class='row'>
                    <div class='col-md-12'>
                        <div id='gallery-slider' class='slider responsive'>
            ";

            foreach ($GalleryImage as $img) {
               //Display this row as many times as needed by data in this row.
               $output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";                     
            }

            $output .= "
                        </div>
                    </div>
                </div>
            ";

            // End gallery row   
            array_push( $checker, $row['ID']); 
        }
    }  


    $output .= "</div>";

    echo $output;
?>

大多数情况下,尝试将
PHP
HTML
分开,这样您就可以很容易地看到错误

$stmt = $db->prepare("query");
$stmt->execute();
$result = $stmt->get_result();

$output = "";
$checker = [];

while ($row = mysqli_fetch_assoc($result)) {
    $ID = $row['ID'];
    $FullName = $row['FullName'];
    $Email = $row['Email'];
    $JobTitle = $row['JobTitle'];
    $Bio = $row['Bio'];
    $Photo = $row['Photo'];

    $GalleryImage = explode(',', $row['GalleryImage']);

    if (isset($Photo) && !empty($Photo)) {
        $ProfileImage = "$Photo";
    } else {
        $ProfileImage = "avatar.jpg";
    }

    if (!in_array($row['ID'], $checker)) : ?>
        <div class='container yep team-wrap'>
            <div class='row'>
                <div class='col-md-6'>
                    <img class='img-responsive' src='cdn/assets/artist/<?php echo $ProfileImage; ?>'>
                </div>
                <div class='col-md-6'>
                    <strong><?php echo $FullName; ?><br><?php echo $JobTitle; ?></strong>
                    <br>
                    <p><?php echo $Bio; ?></p>
                    <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
                </div>
            </div>

            <!--        End of info row-->

            <br/><br/><br/>

            <!--        Start Gallery Row-->
            <div class='row'>
                <div class='col-md-12'>
                    <div id='gallery-slider' class='slider responsive'>
                        <!-- Display this row as many times as needed by data in this row.-->
                       <?php foreach ($GalleryImage as $img) : ?>
                        <img class='img-responsive' src='cdn/assets/gallery/<?php echo $img; ?>'>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
            <!--        // End gallery row-->
        <?php array_push($checker, $row['ID']); endif;
}
?
$stmt=$db->prepare(“查询”);
$stmt->execute();
$result=$stmt->get_result();
$output=“”;
$checker=[];
while($row=mysqli\u fetch\u assoc($result)){
$ID=$row['ID'];
$FullName=$row['FullName'];
$Email=$row['Email'];
$JobTitle=$row['JobTitle'];
$Bio=$row['Bio'];
$Photo=$row['Photo'];
$GalleryImage=分解(“,”,$row['GalleryImage']);
如果(设置($Photo)&!空($Photo)){
$ProfileImage=“$Photo”;
}否则{
$ProfileImage=“avatar.jpg”;
}
如果(!in_数组($row['ID',$checker)):?>
'>





'>
你看不到我在顶部发布的输出看看div所有的末端div你确定你复制的代码正确吗?你显示的结果是如果行
$output.='';
foreach($gallerymage as$img)中,你会得到什么
loop.yes我做了Barmarok,但这也不起作用,因为它只会回显配置文件和1个gallery图像这是我的目标,它会像这样显示数据库中的配置文件
//Start Gallery Row
    $output .= "
        <div class='row'>
         <div class='col-md-12'>
        <div id='gallery-slider' class='slider responsive'>
       ";
} // CLOSED AT THE WRONG SPOT
<?php
    $stmt = $db->prepare("my query");
    $stmt->execute();
    $result = $stmt->get_result();

    $output = "";
    $checker = [];

    while ($row = mysqli_fetch_assoc($result)) {
        $ID = $row['ID'];        
        $FullName = $row['FullName'];    
        $Email = $row['Email'];   
        $JobTitle = $row['JobTitle'];
        $Bio = $row['Bio'];
        $Photo = $row['Photo'];  


        $GalleryImage = explode(',', $row['GalleryImage']);


        if (isset($Photo) && ! empty($Photo)) {
            $ProfileImage = "$Photo";
        } else {
            $ProfileImage= "avatar.jpg";
        }       


        if(!in_array($row['ID'], $checker)) {

            $output .= "
                <div class='container yep team-wrap'>
                    <div class='row'>        
                        <div class='col-md-6'>
                            <img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
                        </div>

                        <div class='col-md-6'>
                            <strong>$FullName<br>$JobTitle</strong>
                            <br>
                            <p>$Bio</p>
                            <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
                        </div> 
                    </div>
                </div> <!-- This was missing-->
            ";

           //End of info row


            $output .="<br /><br /><br />";


           //Start Gallery Row

           $output .= "
                <div class='row'>
                    <div class='col-md-12'>
                        <div id='gallery-slider' class='slider responsive'>
            ";

            foreach ($GalleryImage as $img) {
               //Display this row as many times as needed by data in this row.
               $output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";                     
            }

            $output .= "
                        </div>
                    </div>
                </div>
            ";

            // End gallery row   
            array_push( $checker, $row['ID']); 
        }
    }  


    $output .= "</div>";

    echo $output;
?>
$stmt = $db->prepare("query");
$stmt->execute();
$result = $stmt->get_result();

$output = "";
$checker = [];

while ($row = mysqli_fetch_assoc($result)) {
    $ID = $row['ID'];
    $FullName = $row['FullName'];
    $Email = $row['Email'];
    $JobTitle = $row['JobTitle'];
    $Bio = $row['Bio'];
    $Photo = $row['Photo'];

    $GalleryImage = explode(',', $row['GalleryImage']);

    if (isset($Photo) && !empty($Photo)) {
        $ProfileImage = "$Photo";
    } else {
        $ProfileImage = "avatar.jpg";
    }

    if (!in_array($row['ID'], $checker)) : ?>
        <div class='container yep team-wrap'>
            <div class='row'>
                <div class='col-md-6'>
                    <img class='img-responsive' src='cdn/assets/artist/<?php echo $ProfileImage; ?>'>
                </div>
                <div class='col-md-6'>
                    <strong><?php echo $FullName; ?><br><?php echo $JobTitle; ?></strong>
                    <br>
                    <p><?php echo $Bio; ?></p>
                    <a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
                </div>
            </div>

            <!--        End of info row-->

            <br/><br/><br/>

            <!--        Start Gallery Row-->
            <div class='row'>
                <div class='col-md-12'>
                    <div id='gallery-slider' class='slider responsive'>
                        <!-- Display this row as many times as needed by data in this row.-->
                       <?php foreach ($GalleryImage as $img) : ?>
                        <img class='img-responsive' src='cdn/assets/gallery/<?php echo $img; ?>'>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
            <!--        // End gallery row-->
        <?php array_push($checker, $row['ID']); endif;
}
?