Re: Re: Random Select query

From: Date: Wed, 07 Nov 2001 15:49:12 +0000
Subject: Re: Re: Random Select query
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-73746@lists.php.net to get a copy of this message
Hi Or you could do this... SELECT * FROM mytable ORDER BY RAND() LIMIT 1; but could be slow for large tables.. -- Shane On Wednesday 07 November 2001 4:29 pm, Matt Friedman wrote: > Find the number or rows first. > > then get a random number between 1 and the number or rows. > > then use the limit statement to limit the rows you select to one. make the > offset the random number you generated. that will produce one random row. > then do it three more times. > > Limit works different for different dbs so look up limit in your db docs. > > something like: > SELECT * FROM TABLE LIMIT 1,randomOffsetValueGoesHere > > Matt. > > > ----- Original Message ----- > From: "_lallous" <elias_bachaalany@yahoo.com> > To: <php-general@lists.php.net> > Sent: Wednesday, November 07, 2001 8:34 AM > Subject: [PHP] Re: Random Select query > > > SELECT * FROM TABLE WHERE catid=XXX ORDER BY RAND() > > > > > > "Peter Allum" <develop@connectu.co.uk> wrote in message > > news:20011107132734.46277.qmail@pb1.pair.com... > > > > > Hi there, > > > > > > I am building a website to run tests for people I have a question bank > > of > > > > about 1000, split into 10 categories, Every time the test is taken I > > would > > > > like to randomly select 4 questions from each category. > > > > > > The site is being built using PHP4 & Mysql running on Apache. > > > > > > It is really just the query that I run I need help on though. > > > > > > Thank you in advance for your help. > > > > > > > > > -- > > > Regards, > > > > > > > > > > > > > > > Peter Allum > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#73746) next »