so I'm a bit stuck on this. Ok so, I'm making a small online store, when the user opens the products page a query runs using PHP to get the products from the database and display them on the page. This is the basic query:
SELECT product_id, name, price FROM products ORDER BY RAND() LIMIT 5;
That's running perfectly, the problem is when the user wants to load more products, I run the same query which can cause the same products already displayed to show up again.
Can anyone help, I want to get the products in random order and at the same time not return the products that are already being displayed on my page.
Also, while I was trying to figure this out I came across a question here that says that the RAND()
function in MySQL can cause high load on the server. How can I achieve the same behavior without using the RAND()
function. Any help is greatly appreciated.