Reply to Re: [PHP] Re: using rand()

Your name:

Reply:


Posted by Drewcore on 04/08/05 17:55

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@netsmart.com.cy> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация