SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to add images to my database tables iin SQL server 2008 R2

    Hey guys, I have a table that contains information on products, I want to add an image to each product, and am not sure on which is the best way to do this. i see that there is an image data type in SQL server, some research tells me this is not an advised approach. i was hoping that I could just have a folder in my project called database images and then link each product to its own in image in this folder, so when a query pulls all the info on the product out, then an image is also added to the output.

    Can anyone advise on how this can be done?

    Many thanks!!!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    store the images in a folder, and put the path to the image into the products table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this but which data type is this using? I set teh type to image and it of course required a byte[]. I feel so close!

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    use VARCHAR -- the path you're storing is a character string
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I changed my datatype to varchar and added this in the field of the picture column:
    img src="url"
    then in my out put I run this:
    echo '<br/> picture: '.$row['picture'];

    But it only displays the text stored instead of the grabbing the image from the directory. Is there something wrong with how I am listing the image directory?

    Thanks for your help.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    looks like you forgot the html IMG tag

    store your path string like this: /imagefolder/lolcat.jpg

    then display it like this: <img src="/imagefolder/lolcat.jpg" alt="lolcat">
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I cannot get it to work, but I will keep trying, I cant display it by using the source name, it had to be like this somehow as there will be many images:

    echo '<br/> picture: <img src="'.['picture'].'">;

    I appreciate your help.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    can't help you any further, man, this is the database forum and i don't do php
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You already helped me a lot, thanks man!


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
  •