Stephen,
I usually like to set things either "true" or "false". (or 1 or 0). The true or
false is a little more visual, I think -- so to use your example, I would do it like:
<cfif myQuery.RecordCount EQ 0>
<cfset QueryResults = false>
<cfelse>
<cfset QueryResults = true>
</cfif>
<cfif QueryResults>
There are records
<cfelse>
No records to display
</cfif>
This is reverse of yours (if there are no records, then the variable is false -- your
example shows as true) To me it made more sense to have that variable false.
Of course, you can bypass the whole cfif and use the myQuery.RecordCount and test
whether that is true/false:
<cfif myQuery.recordcount>
There are records
<cfelse>
No records to display.
</cfif>
----- Original Message -----
From: "Adams, Stephen" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, July 16, 2002 5:08 AM
Subject: Writing efficient CFIF statements
> **********************************************************************
> WESTMINSTER CITY COUNCIL
> Please refer to the disclaimer beneath this message
> **********************************************************************
>
> Hi,
>
> I am trying to put more structure into my CF code. My idea is to separate
> the ColdFusion processing from the HTML structure and use CSS for the look
> of the site. I am trying to get an idea of what is the best way to separate
> the CF. I know that I could use custom tags, user defined function and if I
> was using MX, then components. But these are for code that can across used
> in multiple pages. What I am talking about is the CF for an individual
> page.
>
> What has all this to do with CFIF statements, well. I was thinking of
> setting a series of flags that are checked against in my HTML. The CFIF
> statements are there to check the value of these flags and amend the page
> depending on these flags. So I want to be able to write good efficient CFIF
> statements so that my code is up to speed.
>
> Here's an example of what I am talking about:
>
> <!--- Default ColdFusion Parameters --->
> <cfparam name="QueryResults" default="" type="string">
>
> <!--- ColdFusion Processing --->
> <cfquery name="myQuery" datasource="myDSN">
> SELECT *
> FROM myTable
> </cfquery>
>
> <!--- Sets flags --->
> <cfif myQuery.RecordCount EQ 0>
> <cfset QueryResults = 1>
> </cfif>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>
> <html>
> <head>
> <title>Untitled</title>
> </head>
>
> <body>
>
> <cfif QueryResults EQ "1">
> <table cellspacing="2" cellpadding="2">
> <tr>
> <td class="mainFont">Results found.</td>
> </tr>
> </table>
> <cfelse>
> <table cellspacing="2" cellpadding="2">
> <tr>
> <td class="mainFont">No results found.</td>
> </tr>
> </table>
> </cfif>
> </body>
> </html>
>
> This is a simple example, but it shows how I want to keep the processing
> separate at the top of the page.
>
> My question, finally, is how are CFIF statements best written if I want to
> code this way and or is there a better way of writing my CF code.
>
> Thanks.
>
>
> **********************************************************************
> Westminster City Council switchboard:
> +44 20 7641 6000
> **********************************************************************
> This E-Mail may contain information which is
> privileged, confidential and protected from
> disclosure. If you are not the intended recipient
> of this E-mail or any part of it, please telephone
> Westminster City Council immediately on receipt.
> You should not disclose the contents to any other
> person or take copies.
> **********************************************************************
>
>
______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists