this code random images from folder: <?php function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); $num = array_rand($ar); return $ar[$num]; } function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } $root = ''; // If images not in sub directory of current directory specify root //$root = $_SERVER['DOCUMENT_ROOT']; $path = 'images/'; // Obtain list of images from directory $imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList); ?> Place the following where you wish the random image to appear: <img src="<?php echo $path . $img ?>" alt="" /> Please help me change it, comes from database query
If the image paths or even data is stored in a table, you can run a really simple: SELECT image_path FROM image_table ORDER BY RAND() LIMIT 1;
I saved image to database by data type "mediumblob" . not saved web server. now i want slideshow of image.