www.webdeveloper.com
Results 1 to 4 of 4

Thread: random image generator

  1. #1
    Join Date
    May 2006
    Posts
    19

    random image generator

    i know how to make the random quote generator, but how do i make a random image generator, i figure it is the same set up in PHP code but how do you upload them to the mysql database and link them all right?

    Thanks in advance

  2. #2
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    You might want to to store the filename of each image in a MySQL database, then use sql to get a random image Like this:
    PHP Code:
    $selectimg "SELECT * FROM images ORDER BY RAND() LIMIT 1";
    $selectimgquery mysql_query($selectimg);
    $selimg mysql_fetch_array($selectimgquery)

    echo 
    "<a href=\"page.html\"><img alt=\"$selimg[filename]\" src=\"images/graphics/thumbs/$selimg[filename]\"></a>" 

  3. #3
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    PHP Code:
    <?php

    $image_dir 
    './'# customize

    $images glob($image_dir.'*.jpg');

    shuffle($images);

    echo 
    '<img src="'.basename($images[0]).'" alt="random image">';

    ?>

  4. #4
    Join Date
    May 2006
    Posts
    19
    ok well i just wanna use a path then from the database, but how do i put the path in the database and make it work with the right php code?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles