Forum Moderators: coopster
Now, I need an idea on how to create a conditional statement, because not every record has a photo on the server. I need a statement that will select a row at random, check to see if the file exists, and if it doesn't, try another random row.
Is this possible, or practical? Currently, when it loads a row with no image, it shows a generic, "no image available" photo, but this looks really crumby on the page. Which is why I only want to show rows with photos.
Do you have anything in the actual table that says whether there is an attributed photo or not? This could be an option as it would then allow you to select randomly from rows where havepic='yes'.
If there's no other way, I suppose I can call upon my graphic design training, but I hate that crap...
another thought is, grab 10 random rows instead of just 1. that way php can do the selection and you won't have to keep going back to the database. 10 should give you a very high chance of getting 1 or more with images. Then at least the odds of having to show one with no photo are very reduced.
You may want to start with 5 rows and see how that goes. If you find there are still too many with no photos then you could increase it 1 by 1. I would think 10 would be a good cieling number.
instead of however you output it now, you put it in a loop based on your test for the photo, if you find one with a photo then you break [php.net] out of the loop