Page 1 of 1

Random sort issue (page shuffle

Posted: Sat Oct 25, 2008 8:26 am
by lubber123
I have a logic problem concerning running a random search between two numbers to shuffle items on my web page. I do a query to my db and receive the row id's for certain data. What i want to do is find randomly place the items ion my page each time a user comes to my page so that it looks fresh each time. The logic has to find each row randomly and place it on the page only once.

So let's say I retrieve the id's 2, 4, 5, 6, and 9. I want to display its data randomly each time. I thought about placing the id's in an array and then running the random function between the lowest and highest numbers - marking each off when they are discovered. But I think that could take a long time if the number of retrieved id were to grow - finding each number randomly would take a while for the page to load.

Does anyone understand what i am trying to do here and can anyone help?

Re: Random sort issue (page shuffle

Posted: Sat Oct 25, 2008 8:44 am
by VladSun
Do it in DB layer - use ORDER BY RAND() and LIMIT