Hi guys,
I am trying to add futured post into my website, its two columns divs side by side,
I need to select 6 articles from database and display one article as futured in first column and 5 articles in second column.
its seems simple, but my head just stopped working.
And my html first column which I need to display one post in it :
<div class="col-sm-6">
<div class="whats-news-single mb-40 mb-40">
<div class="whates-img">
<img src="..." alt="">
</div>
<div class="whates-caption">
<a href="latest_news.html">Secretart for Economic Air plane that looks like</a>
<p>Struggling to sell one the market wonât stop actress and the and singer Jennifer Lopez.</p>
<span class="small">by Alice cloe - Jun 19, 2020</span>
</div>
</div>
</div
And my html second column which I need to display 5 post in it :
I would love to display first post (without condition) in âfeaturedâ column, but if needed I can add a condition âfuturedâ in database.
first post in first <div class="col-sm-6"> and rest 5 in second <div class="col-sm-6">
No, itâs just SQL related. You create a column for indication. In PHP, you check against that indication to see if itâs the status for âfeaturedâ. If itâs not, wrap it in col-sm-6. If itâs âfeaturedâ, wrap it in col-lg-12 or whatever size you want.
The problem I see with your OP logic is that thereâs no indication so if you want to feature say number 4, you really canât do that. Itâs not as flexible as youâd like it to be. Then the next problem is, I believe SQL orders your query in ascending mode by default. That means if youâre going to make more new articles, youâll only end up with the 6 oldest articles no matter how much new articles you make. So you should order them in descending mode.
If you want to do it based on it being the first post, youâd need to add an order by clause on your query, unless you just want it to be the first that is retrieved, regardless of which one it actually is. As for deciding which <div> to output
Thatâs your post contents, retrieved from the database. I just picked a random variable name, obviously youâll have to change it to use your actual data.
I changed div to components in second example, it works but displays only one article in each. I want it display 1 in firs and 5 in second same as in image.
Youâve changed the variable name in the else clause, or was that just in the forum?
Probably need to see the code as it is now to see why itâs having a problem. I was really just illustrating one way to do something different on the first iteration of a loop.
Thatâs only because of the way the while() loop in that sample code was working. You could easily have used fetchAll() and then used a foreach() loop to step through the array instead. Glad itâs working for you now.