Pulling jpeg name images out of MySQL onto PHP page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MS

    Pulling jpeg name images out of MySQL onto PHP page

    I am new to PHP and MySql. What I would like to do is have my PHP page
    pull the name of an image (jpeg, bmp, etc.) out of MySQL and display
    image from another directory. I don't want the actual image saved in
    the DB, just the name.

    I have the connection established from the Web Page to MySql, all I
    want is how to display the image part. Does anyone have any
    straightforward code to show me how to do this? Is there a better way
    that is not too complicated? Remember, I am a newbie.

    Thanks.

  • Geoff Berrow

    #2
    Re: Pulling jpeg name images out of MySQL onto PHP page

    Message-ID: <1149628332.042 353.148890@y43g 2000cwc.googleg roups.com> from
    MS contained the following:
    [color=blue]
    >I have the connection established from the Web Page to MySql, all I
    >want is how to display the image part. Does anyone have any
    >straightforwar d code to show me how to do this? Is there a better way
    >that is not too complicated? Remember, I am a newbie.[/color]

    Assuming you are storing image names and alt text, this should work

    $path="/images/"; // absolute path to images directory
    $sql="SELECT imagefield, alt_text FROM imagetable";
    $result=mysql_q uery($sql);
    while($myrow=my sql_fetch_array ($result)){
    echo "<img src='$path".$my row['imagefield']."'
    alt='".$myrow['alt_text']."'><br>";
    }



    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • ctclibby

      #3
      Re: Pulling jpeg name images out of MySQL onto PHP page


      MS wrote:
      [snip][color=blue]
      > straightforward code to show me how to do this? Is there a better way
      > that is not too complicated? Remember, I am a newbie.[/color]

      Straightforward ? Boy, am not sure if you want to display this image
      inline or as an image src...

      For inline, you need to open the image file:

      $Image = imagecreatefrom jpeg($ImageName .jpg)

      ..... do stuff with the image here if you wish...

      header("content-type: image/jpeg")
      imagejpeg($Imag e)
      ?>

      Image already exists as a .jpg on disk NOT in a database, create a link
      to it.

      $Query = "select DirFilePath from FileDatabase where
      imagename='Imag eName.jpg'";
      $db = $chk->query($Query );
      .....db error glue stuff here.
      $info = $chk->fetchrow();

      for ease of use, combine your DirFilePath with ImageName.jpg
      ( /usr/local/images/imagename.jpg ) or something like that.
      <img src="/usr/local/images/imagename.jpg">
      ..... more html/php code here.

      your results may vary!

      Comment

      Working...