Forums

This topic is locked

CFIF???

Posted 23 Apr 2003 17:47:50
1
has voted
23 Apr 2003 17:47:50 Penny Andrews posted:
I have a registration page that matches the entered zip code with the zip code in the database. I want to be able to return <CFIF zip.recordcount IS "0">, then.....
How do I do this using both the 5 digit and 9 digit zip code? The database holds both forms and generally people do not enter the 9 digit. Can I write something that calls either the 5 or 9 digit?
All help appreciated
Pen

Replies

Replied 24 Apr 2003 10:45:10
24 Apr 2003 10:45:10 Julio Taylor replied:
is this related to SQL?

------------------------
Julio

PHP | MySQL | DWMX

ICQ: 19735247
MSN:
Replied 24 Apr 2003 11:07:17
24 Apr 2003 11:07:17 Dennis van Galen replied:
Penny,

Is this what you are looking for ?
<pre id=code><font face=courier size=2 id=code>
&lt;cfif LEN(zip.fieldname) EQ 5 OR LEN(zip.fieldname) EQ 9&gt;
logic to be run when zip field contains 5 or 9 characters
&lt;cfelseif #zip.recordcount# EQ 0&gt;
logic for no records
&lt;cfelse&gt;
logic for everything else.
&lt;/cfif&gt;
</font id=code></pre id=code>

with kind regards,

Dennis van Galen
DMXzone Manager
FAQ, Tutorial and Extension Manager


Studio MX / CFMX PRO / SQL 2000 / NT4 AND win2kPRO / IIS5
Replied 24 Apr 2003 17:50:13
24 Apr 2003 17:50:13 Penny Andrews replied:
Yes this is related to SQL. I am validating a cfmx page with a SQL database.
This is what I currently have:

&lt;!--Validate zip code --&gt;
&lt;cfquery name="zip" datasource="sql_database"&gt;
SELECT dbo.Profile.ZIP
FROM dbo.Profile
WHERE ZIP = '#Form.zip#'
&lt;/cfquery&gt;

&lt;CFIF zip.recordcount IS "0"&gt;
&lt;div align="center"&gt;&lt;strong&gt;Please call regarding your account &lt;/strong&gt;&lt;/div&gt;
&lt;cfabort&gt;
&lt;/CFIF&gt;

If the person enters a 5 digit code and we have it listed as a 9 digit code, then the message is to call regarding the account.
divgalen - I tried your suggestion, but am not quite sure where in the sequence to place this.
Thanks for your help!
Pen
Replied 24 Apr 2003 23:50:50
24 Apr 2003 23:50:50 Dennis van Galen replied:
Penny, please try this.
<pre id=code><font face=courier size=2 id=code>
&lt;!--Validate zip code --&gt;
&lt;cfset zip5 = FORM.zip & "%"&gt;
&lt;cfquery name="zip" datasource="sql_database"&gt;
SELECT ZIP
FROM Profile
&lt;cfif LEN(FORM.zip) EQ 5&gt;
WHERE ZIP LIKE '#zip5#'
&lt;cfelseif LEN(FORM.zip) EQ 9&gt;
WHERE ZIP = '#FORM.zip#'
&lt;cfelse&gt;
&lt;!--- Dummy clause to make sure recordcount = 0 if user enters some other length zipcode ---&gt;
WHERE 0 = 1
&lt;/cfif&gt;
&lt;/cfquery&gt;
&lt;cfif zip.recordcount NEQ 0 AND zip.zip EQ form.zip&gt;
&lt;!--- Put the rest of the page here ---&gt;
&lt;cfelse&gt;
&lt;!---
this "else" only runs if there were 0 records or there was 1 record but the entered zip
is not the same as the returned zip, that only happens if user entered 5 digits and the
dbase returns 9 digits. 4 or any other amount of digits returns 0 records so that user
also ends up seeing this message, this is what the dummy clause does 0 is NEVER 1, unless
you happen to have a table called 0 that can have true or false values <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>.
I am not fond of using the cfabort tag, it stops the server more or less, not good for
other application variables.
---&gt;
&lt;div align="center"&gt;&lt;strong&gt;Please call regarding your account&lt;/strong&gt;&lt;/div&gt;
&lt;/cfif&gt;
</font id=code></pre id=code>
I know it's a bit crude, but it gets the job done, i will look some more at it in the morning.

On the other matter...

Your idea of cffile might work even better then cfhttp, but cffile only grabs files from the CF server computer, then again if the CF server is inside a network or can access the other through a physical drive name, IE C:\, D:\, W:\, etc, then you could do it that way.

You need to XMLPa.rse (that triggers bad word filter) it after reading it in, Ben Forta wrote a nice article about reading in XML and putting it to use in CF applications, that could help you further:
www.macromedia.com/devnet/mx/coldfusion/extreme/xml_menu.html

But remember that SQL 2000 can just read in XML and manipulate it, it might be more efficient then having CF pa.rse it just to stick it in a database. It is another matter if you just want to display the xml inside a CF application or use it for further calculations or display through the cfchart tag.

A continuous stream IMO would make the server hang once it starts looping and there is no end to the loop, you definately need a "holding bin", such as the XML you sent me and covered above.
I will also look some more into continuous streams tomorrow and report here if I find something usefull.

Hope this helps alittle.

with kind regards,

Dennis van Galen
DMXzone Manager
FAQ, Tutorial and Extension Manager


Studio MX / CFMX PRO / SQL 2000 / NT4 AND win2kPRO / IIS5

Reply to this topic