Need A Tiny Mihalism Script Mod

Discussion in 'Programming' started by gerritpoel, Jul 15, 2008.

  1. #1
    Hello,

    To make things simple, I need a small modification to my script, that shows a few random thumbnails like on this index page.

    Here is an example for it.

    Anyone got any ideas how I can do that?
    Thanks in advance...
     
    gerritpoel, Jul 15, 2008 IP
  2. ipro

    ipro Active Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    it would be rather easy if you're using a MYSQL database, just append "ORDER BY RAND()" to your query. If you're reading the pictures from a directory you just read all the files into an array and use $image = $array[rand(0, count($array)];
     
    ipro, Jul 15, 2008 IP
  3. gerritpoel

    gerritpoel Active Member

    Messages:
    711
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    70
    #3
    Hey thanks for that fast reply.

    Would I have to include that in a file or write a new one?
    Also, my script opens image with this:
    <# UPLOAD_PATH #> and <# FILENAME #>

    Not sure if thats from Dir or Database, I think Database.

    I'm very inexperienced when it comes down to php and mysql :(
     
    gerritpoel, Jul 15, 2008 IP
  4. ipro

    ipro Active Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    You can try this

    
    $dir = "/file/dir/here/";
    $http = "http://www.domain.com/file/dir/here/";
    $images = array();
    $images_display = 5;
    
    $dh = opendir(w$dir);
    while (false !== ($file = readdir($$dh)) {
            if (strpos($file, ".jpg") != FALSE || strpos($file, ".gif") != FALSE || trpos($file, ".png") != FALSE)
                $images[] = $file;
            }
        }
        closedir($handle);
    
    $echoStr = "";
    
    for($i=0;$i < $image_display; $i++)
    {
        $ran = rand(0, count($images));
        $file = $http.$images[$ran];
         $echoStr = "<img src='$file'/>";
    }
    
    echo $echoStr;
    
    PHP:
     
    ipro, Jul 15, 2008 IP
  5. Aatma

    Aatma Well-Known Member

    Messages:
    1,233
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #5
    does anyone know where the above php hack is supposed to be added to? To sql?
     
    Aatma, Jan 16, 2009 IP