Skip to main content
Inspiring
February 24, 2009
Answered

dynamic image woes

  • February 24, 2009
  • 6 replies
  • 1784 views
I am trying to display anywhere from 1- 7 thumbnails that may or may not be available. The filename for each thumb is stored in the database. All i get is a placeholder instead of an image. I only want to display the image if a filename exists for it in the database. If it does not exist in the database , I do not want to display anything! (image place holder for example). Please see code-- I am novice but getting better - thanks to this forum.


<!---seems to work -a list of projects is generated by passing values in a hotspot's url--->
<cfquery name="cool" datasource="projects">

SELECT endDate, region, county, countyID, roadname, bmp, emp, proj, estcost, authfunds, paid, narrative, software, image1, image2, image3, image4, image5, image6, image7, thumb1, thumb2, thumb3, thumb4, thumb5, thumb6, thumb7

FROM completeTest, completeImagesRecent

WHERE completeTest.projectID=completeImagesRecent.projectID

</cfquery>

<!--- this query is used to pass values to the project details page when a user clicks on a project-- it works--->
<cfquery name="cool" datasource="projects">

SELECT * FROM completeTest,completeImagesRecent
where countyid=#url.countyid#
and completeTest.projectID=completeImagesRecent.projectID
</cfquery>

<!--- finally this code displays six image place holders an no images but does not generate an error--->

<cfoutput>
<cfif #thumb1# EQ " " >
<cfelse>
</cfif>
<img src="#thumb1#" /><br />


<cfif #thumb2# EQ " " >
<cfelse>
</cfif>
<img src="#thumb2#" /><br />


<cfif #thumb3# EQ " ">
<cfelse>
</cfif>
<img src="#thumb3#" /><br />


<cfif #thumb4# EQ " ">
<cfelse>
</cfif>

<img src="#thumb4#" /><br />



<cfif #thumb5# EQ " ">
<cfelse>
</cfif>
<img src="#thumb5#" /><br />


<cfif #thumb6# EQ " ">
<cfelse>
</cfif>

<img src="#thumb6#" /><br />

</cfoutput>

This topic has been closed for replies.
Correct answer Newsgroup_User
<CFQuery name="coolpicx" DATASOURCE="projects">
Select thumb
from completeImages right join CompleteTest on
completeImages.projectID= completeTest.projectID
</CFQuery>

again, you are NOT restricting your query by projectID, thus it returns
ALL images of ALL projects.

add an appropriate WHERE clause to the above query, something like:

WHERE completeTest.projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#some_variable_that_holds_selected_projectID#">

SIDE NOTES:

1) you do not need any JOINs, or even any other table, in the above
query if your completeImages table has a projectID field. this should
work just fine:
SELECT thumb
FROM completeImages
WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#some_variable_that_holds_selected_projectID#">

2) the link to project details page on your page2 looks strange,
specifically this part of the query string:
&projectID=completeTests.projectID"

a) your query is named 'cool', not 'completeTests'
b) you are missing # around the variable

i think that part of your link should be:
&projectID=#cool.projectID#"

if i am right, than the query on your 3rd page should be:
SELECT thumb
FROM completeImages
WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#url.projectID#">

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

6 replies

Newsgroup_UserCorrect answer
Inspiring
February 28, 2009
<CFQuery name="coolpicx" DATASOURCE="projects">
Select thumb
from completeImages right join CompleteTest on
completeImages.projectID= completeTest.projectID
</CFQuery>

again, you are NOT restricting your query by projectID, thus it returns
ALL images of ALL projects.

add an appropriate WHERE clause to the above query, something like:

WHERE completeTest.projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#some_variable_that_holds_selected_projectID#">

SIDE NOTES:

1) you do not need any JOINs, or even any other table, in the above
query if your completeImages table has a projectID field. this should
work just fine:
SELECT thumb
FROM completeImages
WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#some_variable_that_holds_selected_projectID#">

2) the link to project details page on your page2 looks strange,
specifically this part of the query string:
&projectID=completeTests.projectID"

a) your query is named 'cool', not 'completeTests'
b) you are missing # around the variable

i think that part of your link should be:
&projectID=#cool.projectID#"

if i am right, than the query on your 3rd page should be:
SELECT thumb
FROM completeImages
WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#url.projectID#">

hth

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
rockhikerAuthor
Inspiring
March 2, 2009
It works !!! I changed the query to

SELECT thumb
FROM completeImages
WHERE projectID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#url.projectID#">

and I changed the link to: &projectID=#cool.projectID#"


I am trying to dispaly an images unavailabe message if there are no images in the database. pls see code.

<cfoutput query="coolpicx">
<cfif #thumb# EQ " ">

<img src="/crabweb1a/Images/CompleteProjectImages/completeThmbs/#thumb#"/>
<cfelse>
Images unavailable
</cfif>
</cfoutput>




rockhikerAuthor
Inspiring
February 28, 2009
okay! I started over. The county link goes to page that displays list of projects for the selected county. This works. When I click on an indivdual project this I go to the project details page for the selected project. This works and the project details display correctly. The images that go with the details do not. about 400 images display I have not been able to figure out how to display the images for selected project. (got a little further this time)--please see code thks jim
Inspiring
February 25, 2009

<cfdump var="#cool#">

Does that explain anything?

Be careful of multiple columns with the exact same name.
rockhikerAuthor
Inspiring
February 25, 2009
not sure where to put the

<cfdump var="#cool#">
rockhikerAuthor
Inspiring
February 25, 2009
I added
<cfoutput query="cool" group="projectID">
#cool.projectID#

to the project list page and it returned:

Element PROJECTID is undefined in COOL. and I do not see why it is not defined.

jim



Inspiring
February 24, 2009
actually, no, not like that. like this:

<cfoutput query="cool">
<cfloop from="1" to="7" index="x">
<cfif len(trim(cool['thumb' & x][currentrow]))>
<img src="#cool['thumb' & x][currentrow]#" /><br />
</cfif>
</cfloop>
</cfoutput>

but, really, you should probably normalize your db and move all images
into their own table (id [PK], projectID [FK to whatever table has
projectID as PK], image) - that way each project will have as many
images as it needs/has available, not fixed to 7 images.

you also do not need to store thumbnail image names in your db if you
employ a naming convention for your image files: i.e. all thumb images
have names as tn_ + name of full-size image. at least that's what i
usually do - in the least it saves some db space...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
rockhikerAuthor
Inspiring
February 24, 2009
Thanks for the responses - I will try it! and if you look at the select statement the images are in a separate table.

Jim
Inspiring
February 24, 2009
Like this,