html in php

Discussion in 'PHP' started by Sipifi, Mar 8, 2009.

  1. #1
    Hey all,

    As of now i'm using a image rotation script on a main page. It pulls images from my folder and then displays them (nothing fancy)

    Anyway, i'm kinda stuck when it comes to adding a link on it. the script:

    <?
     $imglist='';
     $img_folder = "thumbs/";
    
      mt_srand((double)microtime()*1000);
    
     $imgs = dir($img_folder);
    
     while ($file = $imgs->read()) {
       if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
         $imglist .= "$file ";
    
     } closedir($imgs->handle);
    
     $imglist = explode(" ", $imglist);
     $no = sizeof($imglist)-2;
    
     $random = mt_rand(0, $no);
     $image = $imglist[$random];
    
     echo '<img src="'.$img_folder.$image.'" border=0>';
     ?>
    Code (markup):
    I tried adding the link around it, but then it will just give a link to the main page of the site as php won't read the $image in that part (or so i think)

    Any ideas?
     
    Sipifi, Mar 8, 2009 IP
  2. qualityhostings

    qualityhostings Well-Known Member

    Messages:
    1,764
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    105
    #2
    echo "<img src=$img_folder/$image border=0>";
    Code (markup):
     
    qualityhostings, Mar 8, 2009 IP
    Sipifi likes this.
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    
    echo "<img src=".$img_folder.$image." border=0>"; // if folder variable have / at the end
    echo "<img src=".$img_folder."/".$image." border=0>"; // if folder variable don't have / at the end
    
    PHP:
     
    ActiveFrost, Mar 8, 2009 IP
  4. Sipifi

    Sipifi Well-Known Member

    Messages:
    530
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    155
    #4
    I see what i had wrong now :)

    And so i changed it to:

    echo "<a href='myurl'><img src=$img_folder/$image border=0></a>";
    Code (markup):
    Thanks a lot, qualityhostings. Rep added.
     
    Sipifi, Mar 8, 2009 IP