Michdd Posted May 28, 2009 Share Posted May 28, 2009 Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/159975-solved-selecting-random-entries/ Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this? Sure, you can use pure MySQL to do this: SELECT * FROM table ORDER BY RAND() LIMIT 10 This selects 10 random records from the table. Quote Link to comment https://forums.phpfreaks.com/topic/159975-solved-selecting-random-entries/#findComment-843814 Share on other sites More sharing options...
Michdd Posted May 28, 2009 Author Share Posted May 28, 2009 Is there a way to select random entries with a limit and some where clauses? I know I can do some things like.. put some clauses in an array and random get one (eg. ordering by something different each time) and selecting a random number to start as the lower-limit.. But is there a better way to do this? Sure, you can use pure MySQL to do this: SELECT * FROM table ORDER BY RAND() LIMIT 10 This selects 10 random records from the table. Sorry, this was kind of a waste of a topic.. I should've searched google. I didn't think it was that simple.. Anyway, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159975-solved-selecting-random-entries/#findComment-843816 Share on other sites More sharing options...
Maq Posted May 28, 2009 Share Posted May 28, 2009 I wouldn't consider it a waste, but yeah, Google and a search of these forums could have gotten you the answer. Now there's more for others to reference Quote Link to comment https://forums.phpfreaks.com/topic/159975-solved-selecting-random-entries/#findComment-843820 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.