PHP中关闭if语句和while循环时出现问题

PHP中关闭if语句和while循环时出现问题,php,html,Php,Html,我试图在php的“if语句”和“While”循环中显示一些html。 我不断遇到意外的文件结束错误,我知道缺少两个大括号,但我看不到在哪里正确关闭while循环。 我对编码还是新手,所以请温柔点…:-) 在这里尝试了php语法检查器和其他类似的帖子 <?php include 'includes/header.php';?> <!-- Navigation --> <?php include 'includes/navbar.php';?> <?

我试图在php的“if语句”和“While”循环中显示一些html。 我不断遇到意外的文件结束错误,我知道缺少两个大括号,但我看不到在哪里正确关闭while循环。 我对编码还是新手,所以请温柔点…:-) 在这里尝试了php语法检查器和其他类似的帖子

<?php include 'includes/header.php';?>
    <!-- Navigation -->
<?php include 'includes/navbar.php';?>
<?php
if (isset($_GET['post'])) {
    $post = $_GET['post'];
    if (!is_numeric($post)) {
      header("location:index.php");

    }
}
else {
    header('location: index.php');
}
$query = "SELECT * FROM posts WHERE id=$post";
$run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ;
if (mysqli_num_rows($run_query) > 0 ) {
while ($row = mysqli_fetch_array($run_query)) {
    $post_title = $row['title'];
    $post_id = $row['id'];
    $post_author = $row['author'];
    $post_date = $row['postdate'];
    $post_image = $row['image'];
    $post_content = $row['content'];
    $post_tags = $row['tag'];
    $post_status = $row['status'];
  $img_ext = explode(".", $post_image);
    ?>
    <!-- Page Content -->
    <div class="container">

        <div class="row">

            <!-- Blog Post Content Column -->
            <div class="col-lg-8">

                <!--First Post -->
            <hr>
                <p><h2><a href="#"><?php echo $post_title; ?></a></h2></p>
            <p><h3>by <a href="#"><?php echo $post_author; ?></a></h3></p>
            <p><span class="glyphicon glyphicon-time"></span>Posted on <?php echo $post_date; ?></p>
            <hr>
            <?php if ($img_ext=="mp4"): ?>
                <video controls width="400" height="300">
                <source src="allpostpics/<?php echo $post_image; ?>" type="video/mp4">
                Video tag is not supported in this browser.
                </video>
            <?php else : ?>
                <img class="img-responsive img-rounded" src="allpostpics/<?php echo $post_image; ?>" alt="900 * 300">
                <hr>
                <p><?php echo $post_content; ?></p>
            </div>
            <!-- Blog Sidebar Widgets Column -->
        <div class="col-md-4">
            <?php include 'includes/sidebar.php'; ?>
        </div>
  </div>
        <!-- /.row -->
        <hr>

        <!-- Footer -->
       <?php include 'includes/footer.php';?>
   </div>
     <!-- /.container -->

    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
</body>
</html>


张贴在



PHP在语法上更类似于C,而不是Python或VisualBasic。缩进在这里毫无意义。代码块需要显式地打开和关闭

有两种类型可以引用if-else块,但您没有引用这两种类型

您可以:

如果{…}或者{…}
例如:



您打开了if语句,但忘记关闭它,而在容器关闭后未关闭它。请尝试以下操作:



张贴在



没有相应的
。关闭
元素后。而且在
while
之前不需要
if
,如果没有行,它只需跳过
while
。当然,除非您想在
else
块中显示消息。谢谢大家,底部的End While和End If已经消除了我的语法错误。我现在只需要整理一下视频文件与图像文件的显示(我麻烦的开始),我得到的只是alt=“900*300”显示,所以这部分一定有问题。在另一个页面上,我嵌入了视频文件,没有问题(从mysql数据库条目中提取。$img_ext变量可能有问题。@Michael,已更新!(
endif
太晚,无法输出
$post_内容
)。感谢@Top Master解决了一些问题。另一个问题是我试图“分解”$img_ext,这是一个索引数组,所以我不得不做另一个小改动(注意,[1]一旦我添加了这个,它现在工作得很好。再次感谢。我如何给你“积分”要获得解决此问题的帮助?SO尚不允许您投票,但您应该能够
接受
任何您喜欢的答案;-)(只需单击粗号)