56 users online (0 members and 56 guests)  


Page 1 of 2 1 2 Last
  Results 1 to 15 of 22

Related

  1. Random Images    Forum: PHP Forum
    Replies: 1
  2. Random Images using CSS files    Forum: CSS Forum
    Replies: 3
  3. Random Images Advanced    Forum: HTML Forum
    Replies: 4
  4. random images php script    Forum: PHP Forum
    Replies: 3
  1. #1
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    multiple random images

    i've found (and altered) MANY scripts that display a random image, but i can't seem to find one that doesn't repeat itself when used more than once. here's the table code i'm currently using...

    Code:
    <table width="175" height="1" border="0" cellpadding="0" cellspacing="0" class="left">
    <tr>
    <td height="1" background="images/left_border.gif"><img src="images/spacer" width="175" height="1"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <tr>
    <td align="center" valign="top"><?
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    $randnum1 = rand(0,$nooffiles);
    
    echo "<img src=\"$dir/$files[$randnum1]\" width=\"175\" border=\"0\" class=\"iborder\">"; ?></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <tr>
    <td align="center" valign="top"><? 
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    $randnum2 = rand(0,$nooffiles);
    echo "<img src=\"$dir/$files[$randnum2]\" width=\"175\" border=\"0\" class=\"iborder\">"; ?></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <tr>
    <td align="center" valign="top"><? 
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    $randnum3 = rand(0,$nooffiles);
    echo "<img src=\"$dir/$files[$randnum3]\" width=\"175\" border=\"0\" class=\"iborder\">"; ?></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    </table>
    any takers?
    robert koons

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    hmmm... can you refine a little more? from what i understand, you want a script that will display a random image, but not display the image more than once untill it reaches the end, then it does it again, correct?

    well, are you displaying a bunch of images on one page, but you dont want to display the image more than once on one page, correct? or is it every time somone comes to the page you want to dispay a different image?

  3. #3
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    ok, sorry for being vague... the table code i posted above goes along the left side of the screen. it currently is included on each page of the site and displays three random images from a specific folder. what i did was take a random image script and copied it three times to get the three images to display.

    now, 80% of the time that works fine... but, occasionally two of the three scripts will display the same image. so, i'm thinking there a way to condense the three scripts down to one script that checks itself to ensure no double (or triple) instances of the same image.

    it currently checks itself to not use thumbs.db file, and i was trying alter that code to check for the other instances of random images... but it didn't work for me.

    oh, and i'm only worried about each individual page, not the
    whole site.

    any ideas?
    robert koons

  4. #4
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    well, i am not verry good at php(i am a cgi/perl user), but i will give it a try...
    Code:
    <table width="175" height="1" border="0" cellpadding="0" cellspacing="0" class="left">
    <tr>
    <td height="1" background="images/left_border.gif"><img src="images/spacer" width="175" height="1"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <tr>
    <td align="center" valign="top"><?
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    for($i=0; $i<=3; $i++){
    $randnum[$i] = rand(0,$nooffiles); 
    while($files[$randnum[$i]] == ""){
    $randnum[$i] = rand(0,$nooffiles);
    }
    echo "<img src=\"$dir/$files[$randnum[$i]]\" width=\"175\" border=\"0\" class=\"iborder\">"; ?></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    $files[$randnum[$i]] = "";
    }
    
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    </table>
    Try somthing like that, if that doesnt work (i didnt test it) then try and debug it, or tell me some of the outcomes, and i will try and help more. but it should work, unless i forgot a synthex somewhere.

    -ALL

  5. #5
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    ok, so i've almost got it working. there's one thing missing: the image name. now it's printing //Array(3) instead of the image name.

    here's the code:
    Code:
    <table width="175" height="1" border="0" cellpadding="0" cellspacing="0" class="left">
    <tr>
    <td height="1" background="images/left_border.gif"><img src="images/spacer" width="175" height="1"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr><?
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    for($i=0; $i<=2; $i++){
    $randnum[$i] = rand(0,$nooffiles); 
    while($files[$randnum[$i]] == ""){
    $randnum[$i] = rand(0,$nooffiles);
    } ?>
    <tr>
    <td align="center" valign="top"><img src="<? echo "$dir/$files($randnum[$i])" ;?>" width="175" border="0" class="iborder"></td>
    </tr>
    <tr>
    <td align="center" valign="top"><img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr>
    <? } ?>
    </table>
    here's the output:
    http://www.document-pros.com/left.php
    robert koons

  6. #6
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    Code:
    <table width="175" height="1" border="0" cellpadding="0" cellspacing="0" class="left">
    <tr>
    <td height="1" background="images/left_border.gif"><img src="images/spacer" width="175" height="1"></td>
    </tr>
    <tr>
    <td align="center" valign="top">
    <img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
    </tr><?
    $dir = 'images/left/';
    $dh = opendir($dir);
    
    while (false !== ($filename = readdir($dh))) {
    if($filename == "Thumbs.db" || is_dir($filename)){
    }else{
    $files[] = $filename;
    }
    }
    $nooffildi = count($files);
    $nooffiles = ($nooffildi-1);
    srand((double)microtime()*100000);
    for($i=0; $i<=2; $i++){
    $randnum[$i] = rand(0,$nooffiles); 
    while($files[$randnum[$i]] == ""){
    $randnum[$i] = rand(0,$nooffiles);
    }
    ecno "<tr>\n
    <td align=\"center\" valign=\"top\"><img src=$dir$files($randnum[$i]) width=\"175\" border=\"0\" class=\"iborder\"></td>\n
    </tr>\n
    <tr>\n
    <td align=\"center\" valign=\"top\"><img src=\"images/left_rule.gif\" width=\"170\" height=\"1\" vspace=\"3\"></td>\n
    </tr>\n";
    }
    echo "</table>\n";
    i dont know if that will make much of a difference, but after looking at a few ways of using/creating arrays in php, that is the best way. if that doesnt work, then i am stumped!
    Last edited by ALL; 05-13-2005 at 01:18 PM.

  7. #7
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    still getting the Array(#) for the image name...

    http://www.document-pros.com/left.php
    robert koons

  8. #8
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    stupid me, i should have cought this earlier, "$dir$files($randnum[$i])" i belive when you use "()" insted of "[]" it returns its type (used for debugging[i think])

    use this insted:
    Code:
    $dir$files[$randnum[$i]]

  9. #9
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    error:
    Parse error: parse error, unexpected '[', expecting ']' in /www/d/documentpros/htdocs/left.php on line 28
    robert koons

  10. #10
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    i googled "parse error, unexpected '[', expecting ']' in" and found the problem (i think)

    use this:
    Code:
    $dir$files["$randnum[$i]"]
    this is one of those CGI to PHP differences
    Last edited by ALL; 05-13-2005 at 02:33 PM.

  11. #11
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    hmmm, the "" doesn't work with the echo statement.
    robert koons

  12. #12
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: multiple random images

    try ' '

  13. #13
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /www/d/documentpros/htdocs/left.php on line 28
    robert koons

  14. #14
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: multiple random images

    try 2 things, one i have no idea if it will work, and the other should work, but takes more space then you want, it is unprefered:

    Code:
    $dir$files[$randnum][$i];
    this is the one you want to satay away from if you can:
    Code:
    $temp0 = $randnum[$i];
    temp1 = $files[$temp0];
    //then put this in the expression:
    echo "bla bla bla $dir$temp1 bla bla bal..."
    but like i said, the second one you want to stay away from if you can.
    Last edited by ALL; 05-16-2005 at 08:55 AM.

  15. #15
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76

    Re: multiple random images

    the first solution output wasn't the image name, but rather the random number given to the image.
    <img src=images/left/[0]>

    the second solution output had no image name at all.
    <img src=images/left/>
    robert koons



Page 1 of 2 1 2 Last

Tags for this Thread