I have 2 tables… one for listings and the other for photos… I havnt been able to display one image per listing trying a query within a loop and also a table join… Both options are briging back the same photo for all listings, even listings with no photos…
SELECT listings.listingid
, listings.datelisted
, listings.location
, listings.type
, listings.comments
, MAX(listingphotos.photoname) AS photoname
FROM listings
LEFT OUTER
JOIN listingphotos
ON listingphotos.listingid = listings.listingid
GROUP
BY listings.listingid
by the way, int(25) and int(5) are the same size, they both hold numbers up to 2 billion
If the file details (name, etc) are kept in an array, if you don’t want all the photos then you could use array_rand() on the array containing the photos. If you want all the photos but in a random order then you could use shuffle() on the array. You’ll probably need to have php create an array of the listings then for each listing add a sub-array containing the photos for that listing.
actually, in this case it retrieves the photo with the highest name, not the largest id number
random is a lot harder to do
why don’t you add a column to the listingphotos table, a flag that you can turn on for each listing, on the photo which you want returned as the “default” for each listing
I did think about that, but its more options for the members to set… its not really an issue for what photo is displayed random would have just spiced it up for general browsing