Static block after the first result of a while

-1

How do I put a Static Advertising block after the first result of a while in PHP?

I leave below my while:

while($fetch = $get->fetch()){

}

Type this:

    
asked by anonymous 02.02.2018 / 21:32

2 answers

3

Just use a counter , that is when it is 2 iterating while will do what you want (in this case it will start publicidade ).

And you use continue , to jump to the next iteration.

<?php

$contador = 0;

while($fetch = $get->fetch()){
    $contador++;

    echo "conteudo";

    if($contador == 2){
        //Resultado estatico na segunda vez do while
        echo "publicidade";
    }

}
    
02.02.2018 / 21:42
0

You can add a control variable. It would look something like

$publi = true;
while($fetch = $get->fetch()){
    echo 'conteudo';
    if(publi){
        echo 'publicidade';
        publi = false;
    }
}
    
02.02.2018 / 21:36