Re: note 8046 added to rand

From: Date: Fri, 25 Aug 2000 10:37:42 +0000
Subject: Re: note 8046 added to rand
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-3227@lists.php.net to get a copy of this message
t1@mail.com wrote: > > I've got a dilemna that the above posted solutions won't solve. I've got a > table, > with some rows marked as "active" and others as "in-active". > > I want to randomly select an ACTIVE row. > > Above methods people have posted do not do this. They assume that all rows can be chosen. let the database do it itself: SELECT ... FROM ... WHERE active=1 ... ORDER BY RANDOM() LIMIT 1 > To further complicate matters, I'd like to add a column that specifies a > "probability to be chosen" (for example range 1-5). > Basically I want some rows to have a higher probability to be chosen than others. maybe SELECT ... FROM ... WHERE ... ORDER BY RANDOM()*importance LIMIT 1 should give you lower importance numbers with a hiher probability ... ? -- Hartmut Holzgraefe hartmut@six.de http://www.six.de +49-711-99091-77 fax:-99

« previous php.notes (#3227) next »