显示多个数据但if语句只执行一次

时间:2017-02-26 14:13:12

标签: php database

每个人。我在显示帖子时遇到问题。我正在检查帖子状态,如果帖子状态是发布,那么它将显示帖子。其他明智的不是.while循环正常但是如果语句只执行一次。我的意思是如果语句只执行一个帖子,则有3个帖子具有发布状态。 我回应它发布三次的帖子状态。 我知道原因。 请帮我。 感谢

              <?php
              $query="SELECT * FROM posts";
              $result=mysqli_query($con,$query);

               while($row=mysqli_fetch_assoc($result)) {

                 $post_title = $row['post_title'];
                 $post_id = $row['post_id'];
                 $post_author = $row['post_author'];
                 $post_date = $row['post_date'];
                   $post_image = $row['post_image'];
                  $post_content = substr($row['post_content'], 0, 100);
                  $post_status = $row['post_status'];
                  echo $post_status;
                  echo "<br>";

               if($post_status=='Draft') {
                  echo "<h2>NO POSTS SORRY</h2>";

              };
               if($post_status=='Publish') {

                ?>
              <h1 class="page-header">
                 Page Heading
                <small>Secondary Text</small>
            </h1>
              <!-- First Blog Post -->
              <h2>
                  <a href="post.php?p_id=<?php echo $post_id; ?>"><?php echo $post_title; ?></a>
              </h2>
            <p class="lead">
                  <a href="index.php"><?php echo $post_author; ?></a>
              </p>
              <p><span class="glyphicon glyphicon-time"></span> <?php echo $post_date; ?></p>
               <hr>
              <img class="img-responsive" src="Images/<?php  echo $post_image; ?>" alt="">
              <hr>
              <p><?php echo $post_content; ?></p>
              <a class="btn btn-primary" href="#">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>
                  <hr>

               <?php   }};?>

0 个答案:

没有答案