Quick Tip: PHP MySql Pagination with Random Ordering

I recently got to work a site which was more like a directory. One of main trick there was to show random advertiser on the site so that each advertiser get’s some┬áchance for displaying on sites front page. That was actually easy until this has to go with pagination. Back then I didn’t even knew if there’s any way to achieve mysql pagination with random ordering.

Problem is, you show some random advertisers on 1st page but on second page you must see another set of random advertisers (excluding what you already seen on 1st page) and so on. you see where’s it’s going?

Mysql Rand(seed) function to rescue

SELECT * FROM your_table ORDER BY RAND(351) LIMIT 10, 10;

Continue reading