Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mazinoukah's avatar

How to create a featured/Top article in a classifieds php application

I'm creating a PHP classified ads application but i'm stuck on how to create the 'Top Ads/Featured Ads section' to be shown at every search page depending on the category. My first instinct was to create an sql query to randomize these 'Top ads' , Limit the result to 2 and display it on each search page. However its seems this is going to break quickly as i'm using " order by Rand() " in my query to randomize the result. Please how can i achieve this using a more practical approach ?

0 likes
3 replies
RachidLaasri's avatar

Order them by most viewed? Add a 'views' column to your table and increment it when someone sees the ads.

mazinoukah's avatar

@RachidLaasri The Top Ads section is for displaying "paid ads" (and there re different promo plans), if i should order it by most viewed , someone who paid for that feature might never find his ad at that Top ad section. i'm already using the order by most viewed for the section below that displays the free ads (ads without the featured plan).

blueclassy's avatar

to make a top ads you can create a separate column in your ads table which can identify the priority levels of the ads and sort by priority which will make your ad to ads once the priority meets.

just like we did it here on adclassified's latest ads page which is another free classifieds website built on blue classy.

Please or to participate in this conversation.