hal helm's logo  
home Home

training Training

writing Writings

code Code

tutorials Tutorials

newsletters Newsletters

consulting Consulting

Hal Helms logo
hal.helms

What Students Say...

"This was the best class I ever attended." - Sung W.

"Really, the class was outstanding. My confidence level is up 100%. I just got finished showing Wireframes and DevNotes to the gang in the office, along with a quick overview of Fusedocs. We are a VERY happy group of developers. Most of them have had some exposure to Fusebox and seeing it in the context of a development lifecycle has generated a lot of enthusiasm. We're already seeing significant performance gains. It's going to take some time to get everyone up to speed, but there is a sense of a turning point in the war." - Oliver E

"This class changed the way I think about about programming and about my career." - Brandon H.

tutorials section

Why won't my code display anything when my query returns nothing?

The Situation: You have executed a query and then want to display the results of that query using <cfoutput>. All works well -- unless your query doesn't return any rows. Then, nothing displays.


Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors

The Solution: When used with the "query=" parameter, <CFOUTPUT> acts as a loop, iterating through each row returned by the query. If you don't have any rows returned, it will skip over ALL the contents between the <cfoutput></cfoutput> tags so that if the query below returns no rows, the output on the screen will be blank.


<cfquery datasource="aDatasoruce" name="myQ">
  SELECT userID, userName 
  FROM Users
  WHERE fullname = 'Hal Helms'
</cfquery>

<cfoutput query="myQ">
  Your user ID number is #userID#
</cfoutput>

If the query "myQ" did not return at least one row, the code inside the <cfoutput> will never evaluate. To prevent this, you want to test the RECORDCOUNT property of the returned query.


<cfif myQ.recordcount GT 0>
  <cfoutput query="myQ">
  Your user ID number is #userID#
  </cfoutput>
<cfelse>
  Sorry, we couldn't find you in our database.
</cfif>
©copyright      designed by in-tuition.co.uk
hal helms' personal site Updates

Computers are incorporated in modern ice cream vending machines to enhance their functionality. Ice Cream Vending machines are manufactured by many companies. Your competition will try to overcome all requests for high-tech ice cream vending machines and credit card acceptors

teamallaire.com v 4_3