1
I have a recipes website where I bring the list of recipes according to the query below:
SELECT * FROM receitas WHERE titulo LIKE '%batata%' ORDER BY ordem
I wanted to show the first 3 featured results (with a different CSS class) and the rest below.
I thought to do 2 foreach, the first with the first 3 highlight and the other foreach with the rest of the results.
My question: This is the best way? If yes, how can I make the 2nd foreach discount those who have already appeared in the 1st not to repeat?
I would like the end result to be:
<h2>Destaques</h2>
<div>
<div class="destaque">Destaque 1</div>
<div class="destaque">Destaque 2</div>
<div class="destaque">Destaque 3</div>
</div>
<h2>Outros</h2>
<div>
<div class="comum">Outro 1</div>
<div class="comum">Outro 2</div>
</div>
show, is that like joining the foreach with the is? a doubt on this, is that I would like to put a <H2> between the highlights and the common ones, I edited my question as I need the final result.
– Leandro Marzullo
I got it using what you sent and a combination of ifs, I can edit your reply and put as solved?
– Leandro Marzullo
Hello. Foreach and For are efficient loop loops, but foreach is used to traverse arrays or objects. I’m glad you made it! Yes, you can.
– Rohan