mardi 19 mai 2015

Randomly select image an from directory using php and use its filename for a mysql query

I have a directory of images which are all named *.jpg, where * is the ID of each record in a MySQL table. e.g. 1394.jpg

What I'd like to be able to do is pull 5 random images from that directory using PHP and for each image, then query the MySQL table for records matching that ID / image filename, so I can then display details of each record.

The part I am looking for some guidance on is how to a) randomly choose 5 images using php, then b) identifying the filenames. Once I have the filename as a variable, I am sure I should be able to write the MySQL query. It's the PHP element I'm struggling with.

Could anyone offer any advice?




Aucun commentaire:

Enregistrer un commentaire