I need premium ads to always appear in the first place in the general list of ads (up to 15 items), but only to a limited extent (up to 5 items). Those. There can only be 20 ads per page.
at first I tried to make a general selection sorted by premium, but it didn’t work out quite right, because. all premium will be the first to go in the search results.
decided to make two separate selections (
select count) and merge the result (
array_merge). But I ran into a pagination problem that I don’t understand how to solve: let’s say the premium selection gave 10 pages (9 pages of 5 pages each, 10 pages – 2 pages), and the usual selection gave 3 pages.
On the site, I get ready-made 3 pages, on which everything is visible as it should, but because premium took 10 pages, then the premium part is already lost.
Tell me the logic of actions, otherwise I'm confused! Thank you.
You can use UNION. First request with LIMIT 5.
(SELECT * FROM `table1` WHERE `is_premium` = 1 LIMIT 5) UNION (SELECT * FROM `table1` WHERE `is_premium` = 0);