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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I dynamically populate images using a database and CF?

Dynamic Population

How do I dynamically populate images using a database and CF?

by  ecobb  Posted    (Edited  )
I do this with several sites. I usually have a field in a table for the image file name (image1.jpg, for example). Then I make sure all of the images are in a specific folder (ImageFolder, for example). Then in my cfquery, I have it select the image name from the table, and I have it output into a html image tag.

Example:

[color maroon]
<CFQUERY datasource="MYDSN" NAME="GetDocs">
SELECT Record1, Record2, Record3, Image
FROM tbl1
</CFQUERY>

<cfoutput>[/color]
<img src="whateverdirectory/ImageFolder/#Image#>
[color maroon]</cfoutput>[/color]

This would output in the HTML as:
<img src="whateverdirectory/ImageFolder/image1.jpg>

Or, if you didn't want to have all of the images in the same folder, you could store part of the image path (ImageFolder/image1.jpg, for example) in the database and use it like this:

<img src="whateverdirectory/#Image#>

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top