Results 1 to 5 of 5

Thread: PHP Random image 3 images in a row

  1. #1
    Join Date
    Jan 2009
    Posts
    46

    PHP Random image 3 images in a row

    I have a random image script.
    But I want so that 3 different photos you can see in a row.

    I have therefore tried

    Code:
    <?
    $ folder = ". / screens / '/ / The directory of the images a. for the same folder where this file.

    $ dir = opendir ($ folder);
    / / Get the data dir
    while (false! == ($ file = readdir ($ dir)))
    (
    if (($ file! == ".") & & ($ file! == ".."))
    (
    list ($ filename, $ ext) = explode (".", $ file);
    $ ext = strtolower ($ ext);
    if (($ ext == "jpg") | | ($ ext == "png") | | ($ ext == "poison"))
    (
    $ image [] = $ file;
    )
    (
    $ afbeelding2 [] = $ file;
    )
    (
    $ afbeelding3 [] = $ file;
    )
    )
    )
    closedir ($ dir);

    / / Counts number of images in folder and creates a random number from that number.
    $ number = count ($ image) - 1;
    $ rand = mt_rand (0, $ number);
    echo "<img src=\"".$map. $afbeelding[$rand]."\" width=136 height=111>;
    echo '';
    echo "";
    echo "<img src=\"".$map. $afbeelding2[$rand]."\" width=136 height=111>;
    echo '';
    echo "";
    echo "<img src=\"".$map. $afbeelding3[$rand]."\" width=136 height=111>;
    >


    but that does not work: (I still get 3 the same pictures in a row.

    I would also like to have them clickable so that if there is a popup with the photo.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: PHP Random image 3 images in a row

    Do you love that you see the same photo 3x ..? Then you something better to look at your code.

    You take in 3x the same random value from a 'copy' of the same array. When you first check whether the extension matches (and that is probably in your case always) and in the other arrays, all files (in your case the same as array 1).

    Instead of the 3 arrays can better address 3x a random number and compare with the numbers that you already had it

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: PHP Random image 3 images in a row

    Clickable images, for example, :


    php:

    <?
    echo "<a href=\"" . $afbeelding [ $rand ]. "\"><img src=\"" . $map . $afbeelding [ $rand ]. "\" width=136 height=111></a>" ;
    ?>

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: PHP Random image 3 images in a row

    Keeping the picture you have already used. And in this case you would the photo from the array may flicker.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: PHP Random image 3 images in a row

    For the same topic to a conclusion:
    After the folder is selected, place the following code:

    php:

    <?
    $ number = count ($ image) - 1;
    $ i = 0;
    $ selected = array (), / / array to create images which are
    while ($ i <3) (
    $ rand = mt_rand (0, $ number);
    if (in_array ($ rand, $ selected)) (
    / / do nothing graphic is selected
    ) else (
    / / Add image to $ selected images
    $ selected images [] = $ rand;
    $ i + +;
    )
    )
    / / ok 3 selected still image display
    foreach ($ selected images as $ value) (
    echo "<a href=\"". $map. $value. "\"> <img src=\"". $map. $value. "\" width=136 height=111> </ a>";
    )
    >

Similar Threads

  1. Getting random white Pixel inside Black image on Mozilla Firefox 6.0
    By gANdHAaIt in forum Technology & Internet
    Replies: 6
    Last Post: 25-08-2011, 10:30 AM
  2. Replies: 3
    Last Post: 23-11-2010, 10:03 PM
  3. Image Clip Hunter for images
    By CrazeD in forum Windows Software
    Replies: 3
    Last Post: 27-10-2009, 11:54 AM
  4. How to display random image in CSS ?
    By $tatic in forum Software Development
    Replies: 4
    Last Post: 16-01-2009, 06:25 PM
  5. Random images in CSS
    By CitricAcid in forum Software Development
    Replies: 7
    Last Post: 04-12-2008, 01:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,263,286.94975 seconds with 17 queries