11 Replies Latest reply on Feb 7, 2007 9:00 AM by talsri

    Show Image in a dynamic table

    talsri
      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.
        • 1. Re: Show Image in a dynamic table
          Charlie Griefer Level 1
          i'm not sure i'm following. what exactly is the issue you're having?
          • 2. Re: Show Image in a dynamic table
            Giles_B
            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.
            • 3. Show Image in a dynamic table
              talsri Level 1
              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.
              • 4. Re: Show Image in a dynamic table
                mvierow Level 1
                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"/>
                • 5. Re: Show Image in a dynamic table
                  talsri Level 1
                  how would I modify the code if the image type is not JPEG?
                  • 6. Re: Show Image in a dynamic table
                    talsri Level 1
                    I appreciate your time. One question though.
                    how would I modify the code if the image type is not JPEG?
                    • 7. Re: Show Image in a dynamic table
                      mvierow Level 1
                      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.
                      • 8. Show Image in a dynamic table
                        talsri Level 1
                        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.
                        • 9. Re: Show Image in a dynamic table
                          azadisaryev Level 1
                          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.
                          • 10. Show Image in a dynamic table
                            talsri Level 1
                            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#">
                            • 11. Re: Show Image in a dynamic table
                              talsri Level 1
                              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.