SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Lance's Avatar
    Join Date
    May 2005
    Location
    Maine, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using image filesnames once they are retreived from mySql

    Ok, so I've stored some image filenames in mysql... my query grabs them, brings them in, now I cant figure out how to assign the filename toa variable, so i can use it as an image source...
    I'm using PHP...
    Thanks in advance!

  2. #2
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Lance:

    Typically you iterate over the result that is returned for instance you could have something as such:

    while($image = mysql_fetch_assoc($result)) {
    $img = '<img src="' . $image['filename'] . '" />';
    }

    Replace 'filename' with the column name of where you stored the filenames. And this is assuming you have already connected to the database and queried it for the data.

    You could optionally go the object oriented route and for that I recommend you read Harry Fuecks article here on Sitepoint (which is also part of his excellent book) - > http://www.sitepoint.com/article/php...gy-3-php-mysql

    John

  3. #3
    SitePoint Zealot Lance's Avatar
    Join Date
    May 2005
    Location
    Maine, USA
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks!

    This is exactly what I needed, thanks again!

  4. #4
    SitePoint Zealot ohnnyj's Avatar
    Join Date
    Jun 2003
    Location
    California
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could help, just remember that this was just a simple example, be sure you know the path to the image files from the page you are using this code. For instance if you have an images folder and the page is in your root directory it would be something like such:

    $img = '<img src="images/' . $image['filename'] . '" />';

    And if the page were in a subdirectory you would have something like:

    $img = '<img src="../images' . $image['filename'] . '" />';

    Of course you could always do absolute paths but I tend to shy away from them when I can. And then there is mod_rewrite in Apache but that is a whole other story.


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
  •