Re: using rand()

From: Date: Fri, 08 Apr 2005 14:41:13 +0000
Subject: Re: using rand()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-212644@lists.php.net to get a copy of this message
first I would suggest you get the largest value from the auto increment field (maybe use last_insert_id()). Then use rand(1,$cno_max) three times to get three random cno numbers, then "select ... from ... where cno=$val1 or cno=$val2 or cno=$val3" should return the three values. rand() can also be directly in the sql statement. Also manual suggests using mt_rand instead of rand for better performance. K.Sakkas Ryan A wrote: > Hey, > need some advise on what would be the best way to do this: > > I have a table with these fields: > cno (just a auto_increment field), > username, > sex (2 values: man, woman), > has_pic (0=no,1=yes), > pic_name > > I need to randomly get 3 womens pictures and one guys picture from the above > table... > I know I need to use rand() and i thought maybe shuffle() but am getting a > bit lost in the logic part...help please? > > Thanks, > Ryan > > > -- Kyriacos Sakkas Netsmart Development Team Tel: + 357 22 452565 Fax: + 357 22 452566 kyriacos(at)netsmart.com.cy http://www.netsmart.com.cy Taking Business to a New Level!

« previous php.general (#212644) next »