Sign in
Log inSign up

What do you think of Pagination with an Order By rand() clause?

Lila Fowler's photo
Lila Fowler
·Jan 4, 2019

I'm building an online store as a project, and I think it'll be cool to see new different content with each page refresh i.e. each time a user comes to the website, he'll see different content on the font page even if no new products were added.

I don't know of any ways the code can 'break' or be user 'unfriendly', I haven't checked the possibilities. What do you think?

Here's the query:

SELECT
        SQL_CALC_FOUND_ROWS
        name,
        id
    FROM
        products
    ORDER BY 
        rand() 
    LIMIT
     .........(php calculation to make the pagination work).........

I tested it out and noticed that no duplicates appear across pages (which is the only problem I see with sorting by random), I think that's cause of the super cool pagination-library I'm using. Unless it's just a coincidence....

Nah, it can't be a coincidence across 1,000 rows!

So what do you think?

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct