如何在关联数组中跳过while循环的迭代意味着我们想要像这样执行第一,第二,第四,第五?

问题描述 投票:0回答:1

我正在创建一个CMS系统。如果post没有发布那么它将不会在html中呈现,否则在html中显示。因此,如果我从数据库“cms”获取一个关联数组,那么它有一些已发布和未发布的帖子。那么我怎么能跳过未发表的帖子,只显示html中发布的帖子。

我试过条件

            <!-- First Blog Post -->
            <h2 style = "color:green;">
                   <?php echo $post_title ;?></a>
            </h2>
            <p class="lead">
                 by <?php echo $post_author ;?></a>
            </p>
            <p><span class="glyphicon glyphicon-time"></span><?php $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 } ?> **    
     **<?php } **// <!--loop ends here so that we can fetch 'n' no. of posts and displaying each post like below HTML -->

                ?>
        </div>

如果发布==发布,那么只在html中显示它,否则不显示它。

php associative-array
1个回答
1
投票

检查是否在循环开始时发布了帖子。然后使用continue跳过循环的其余部分。

while(items) { if(!$post->published) continue; // this part only runs if post is published }

© www.soinside.com 2019 - 2024. All rights reserved.