Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying an Image from an SQL Server Database

Status
Not open for further replies.

wpollack

MIS
Aug 30, 2002
2
US
I am trying to display an in that is in an SQL Server database. I am using the NorthWind database for testing. In the Employees table, there is an image datatype column. All I want to do is query the database and display the picture of the employee with his/her name. How do you do this?

My query is <CFQUERY>SELECT * FROM EMPLOYEES</CFQUERY>

The name of the image column is called Photo.

 
You'd have to set the src attribute of the <img> tag to a .cfm page (the &quot;image page&quot;, we'll call it) that queried the database for the binary data for just one photo, given the id for the row. Then, in your main page, you'd query the database for all the rows with their ids and write a bunch of <img> tags that call the &quot;image page&quot; for each id. I'm not sure about exactly how to output the binary data, although I'd guess it would have something to do with <cfcontent>.
 
I read something about that, but no one seems to have any code on how to do this. I also read something about using the <CFFILE> tag with the ToBase64 function, but no one has any code for that, too.
 
You might want to consider going the easy route -- put the images in a folder and use the database to keep track of the image names, not the image data itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top