Re: Re: using rand()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



i guess a good question would be which one of these methods has more
overhead - having php calculate the random numbers for queries, or
having the mysql db pick them at random itself? i don't really focus
that much on optimization, but if you expect heavy traffic on your
site, it might be in your best interest to find out which one executes
quicker.


On Apr 8, 2005 9:41 AM, kyriacos sakkas <kyriacos@xxxxxxxxxxxxxxx> wrote:
> 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!
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-- 
dc .. drewcore.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux