Static block after the first while result

Asked

Viewed 68 times

-1

How do I place a static block of advertising after the first result of a while in php?

I leave down my while:

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

}

Like this:

Resultado do while em php

  • The question is about how to format the results side by side or how to build the php code that brings the static result in 2nd place?

2 answers

3


just use a accountant, or when it is 2 iteration in while will do what is desired(in this case will print publicidade).

And you use the 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";
    }

}
  • 1

    If you use the continue, you will always lose the second record as it will not run the echo.

  • And how do I not lose the second record?

  • @Andersoncarloswoss edited. Bruno just test the condition after showing the content.

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;
    }
}
  • I confess I didn’t understand!

  • Consider putting the question as answered

Browser other questions tagged

You are not signed in. Login or sign up in order to post.