If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Random select

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-08, 10:45
xixo xixo is offline
Registered User
 
Join Date: May 2004
Posts: 78
Random select

Hi all,

I've got a table with people information, and a second table with photos regarding those people. The people could have one or more photos.
My problem is to get a random photo for each person.

Does anyone have an idea...

Many thanks.
Reply With Quote
  #2 (permalink)  
Old 12-17-08, 14:13
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Do you need a random photo for one person, or a group of people (one photo each)?
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 12-18-08, 04:44
xixo xixo is offline
Registered User
 
Join Date: May 2004
Posts: 78
a need a random photo for everyone (1 person 1 photo)
Reply With Quote
  #4 (permalink)  
Old 12-18-08, 04:50
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
have a look at the MySQL RAND function

you will need to take appropriatye note of the performance implications of using rand to select images

it may work on a subselect
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 12-18-08, 05:13
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Does RAND not just return a single value per dataset, rather than per row?
(I'd love to look it up in the link you posted, but dev.mysql doesn't seem to load from this location!)
__________________
George
Twitter | Blog
Reply With Quote
  #6 (permalink)  
Old 12-18-08, 05:36
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
I'll try to dig out some code I've used before.. it grabs random images (well URL's to images) from a MySQL DB. IIRC the code grabbed 30 images from a pool of 5000+. it was used on a website to display the range of products sold, although we only used 15.. the over was to allow for images that were not found when the script actually ran (to avoid having to go fetch another random selection of images).
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #7 (permalink)  
Old 12-18-08, 05:43
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
....just checked
its a standard SQL select statement with an order by clause of
Code:
order by RAND() LIMIT 32
however there is a note in the MySQL manual that Rand can be a resource hog... we use it to grab 32 images once, not grab a random image for every person.. I suspect this will have a significant performance impact (assuming this is a live requirement and not a piece of homework).
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On