在PHP中三个循环后,如何回声



我有一个场景,而我需要在PHP中每三个项目循环后打印一个广告。我正在数据库中的100个视频循环,在每三个视频计数循环之后,它应该回应广告并继续,它在每三个视频之间回荡图像

喜欢

<div>1<div>
<div>2<div>
<div>3<div>
ADVERT HERE
<div>4<div>
<div>5<div>
<div>6<div>
ADVERT HERE  ......... and so on

以下是我尝试的

<?php 
$qsel = "SELECT * FROM video_post ORDER BY sn DESC";
$results = mysqli_query($conn,$qsel) or die(mysqli_error());  
$num_rows = mysqli_num_rows($results);
$i = 0;
while($rows=mysqli_fetch_array($results)){
    $i = $i++;
    $status = $rows['status'];
    $usern = $rows['username'];  ?>

        ///the advert
        <?php
        if($i == 3){
            print '<div class="wrapper">
                <div class="image">
                <img  src="advert/advert 4.jpg" alt="Slide 1" style="width: 65%;">
                </div>
                </div>';
            // $i=1;
        }   ?>

    <video width="320" height="240" class="embed-responsive-item" controls>
        <source src="video/<?php echo $video ; ?>" type="video/mp4">
        Your browser does not support the video tag. 
        </video>

        <?php } ?>

modulo(%(是您的朋友https://secure.php.net/manual/manual/en/language.operators.arithmetic.arithmetic.php

更改

 if($i == 3){

to

 if( ($i % 3) == 0 ){

最新更新