• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Show Image in a dynamic table

New Here ,
Feb 01, 2007 Feb 01, 2007

Copy link to clipboard

Copied

I have a dynamic table where I would show these columnd event_id,event_desc,event_date anf for each Event, in it's own column I want to display the image that is attached to that Event. Does any body put me in right direction.
TOPICS
Advanced techniques

Views

822

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Feb 05, 2007 Feb 05, 2007
follow mvierow's advice properly:
put his code in a SEPARATE cfm page.
then call that page from within the <img src=" tag as he has shown you.
make sure you DO NOT have any <!DOCTYPE, <html, <meta, <head, <body, etc tags in that separate page - right now you are declaring in your <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> that the page is text/html instead of img/jpeg.
also make sure your image in the db is actually jpeg and not png/gif/etc.

Votes

Translate

Translate
Guest
Feb 01, 2007 Feb 01, 2007

Copy link to clipboard

Copied

i'm not sure i'm following. what exactly is the issue you're having?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

ok... I think I was not clear... sorry about that.
I am kind of new to Coldfusion.
this is what I want to accomplish.
I want to show a list of events that people can buy tickets for.The events would be listed in a dynamic table.
The source of the data is a table called EVENT. Each event has a sponsor image stored in the the EVENT table.
What I want to do is .... I want to display that image for each event in the same row as event_date event_time and Event_description. I can't store it in a file on the server, because I have more than 150 clients ( with atleast 100 different events every year) using this web page. And also I have to apply the same solution to all the retail items they wish to sell.
I am looking for a sample code or just right direction to accomplish my task. In our legacy code ( SIlverStream) we use servlets to handle the images from databases and then in the Image tag we simply pass the url with serverlet.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

You'll need to create a second template to display the image. In that template you can pull the content from the db and display it using the cfcontent tag. Something like so..

<cfparam type="numeric" name="url.event_id" default="0"/>
<cfquery name="getImage" datasource="#ds#">
select event_image from events where event_id = <cfqueryparam value="#url.event_id#" cfsqltype="cf_sql_integer"/>
</cfquery>
<cfcontent type="image/jpeg" variable="getImage.event_image"/>

Then in your table, you just do
<img src="templatename.cfm?event_id=12345"/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

Store the image name in the database (you could use event_pic to follow your naming convention) then use that in an image tag in the last column.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

how would I modify the code if the image type is not JPEG?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

I appreciate your time. One question though.
how would I modify the code if the image type is not JPEG?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2007 Feb 02, 2007

Copy link to clipboard

Copied

If every image is the same format, just enter the type.. image/jpeg, image/gif.. etc. If you have different image formats, you'll need to store that format in another column. Then just select the binary data and the format in your query at the same time. You must provide some kind of format if you want the browser to actually interpret the data as an image and not display the broken image icon.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2007 Feb 05, 2007

Copy link to clipboard

Copied

I am attaching the code ... can you see what am I doing wrong.
I also enabled the "Enable binary large object retrieval (BLOB)."
I don't get any errors but I don't see my images either. I know for sure that I have 3 events with images of type .jpg.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2007 Feb 05, 2007

Copy link to clipboard

Copied

follow mvierow's advice properly:
put his code in a SEPARATE cfm page.
then call that page from within the <img src=" tag as he has shown you.
make sure you DO NOT have any <!DOCTYPE, <html, <meta, <head, <body, etc tags in that separate page - right now you are declaring in your <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> that the page is text/html instead of img/jpeg.
also make sure your image in the db is actually jpeg and not png/gif/etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2007 Feb 06, 2007

Copy link to clipboard

Copied

Guys,
As I said earlier I am very new to CF. I don't know what I am doing wrong. here is what I have. By the way... I really appreciate everybody's time.
I have fr_events.cfm with this following code

<cfquery name="Recordset1" datasource="#Application.databaseDatasource#"
username="#Application.databaseUsername#"
password="#Application.databasePassword#">
SELECT event_id,event_date, event_time, (case when event_visitor is null or event_visitor ='' then event_home else event_visitor || ' @ ' || Event_home end) as event, (select count(*) from tms.web_event_seat where event_id=tms.event.event_id and status='7') as tickets
FROM tms.event where event_date>today()
ORDER BY event_date ASC
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Barnstormers Tickets</title>
</head>

<body>

<table border="1" cellpadding="1" cellspacing="1">

<cfoutput query="Recordset1">
<tr>
<td>#Recordset1.event# <br />#dateformat(Recordset1.event_date,"mmmmm dd, yyyy")#<br>
#timeformat(Recordset1.event_time,"h:mm tt")#
<cfif #Recordset1.tickets# le 0>
<br /> <font color= color="##FF0000"> PLEASE CALL 1-800-800-8788
<cfelse> <br />
<img src="fr_search_for_tickets.gif" /></cfif>
<td> <img src="event_images.cfm?event_id=#recordset1.event_id#"/>
</tr>
</cfoutput>
</table>
</body>
</html>
and Event_images.cfm with the following code and I have JPG files attached to every event_id.
as Per Sabaidee's suggestion I took out all tags from this page . I still don't get my images displayed? Help please!!!

<cfparam type="numeric" name="#url.event_id#" default="0"/>
<cfquery name="getImage" datasource="#Application.databaseDatasource#"
username="#Application.databaseUsername#"
password="#Application.databasePassword#">
select image from tms.event where event_id = <cfqueryparam value="#url.event_id#" cfsqltype="cf_sql_numeric"/>
</cfquery>


<!---<cfcontent variable="getImage.event_image"/>--->
<cfcontent type="image/jpg" variable="#getImage.image#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2007 Feb 07, 2007

Copy link to clipboard

Copied

LATEST
I want to thank mvierow and Sabaidee for putting me in right direction.
It works now. all I did was change couple of things.
I have to change my sql statement to to have an alias for my image column ( for some stupid reason they named it as IMAGE , which might be a reserved word).
also i had to add fac=mydatasource name in the Event page. ANd it works great.

I am every thankful for all your suggestions. Sorry... if I ever frustrated you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation