Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping in Cold Fusion 1

Status
Not open for further replies.

anastasia

Programmer
Dec 13, 2000
111
GB
I have the following code which is created in ASP. I have this in an application that tests a time entered by the user in an input box to times stored in a database such as 08:00, 08:15 etc at 15 minute intervals until 20:00 so quite a few times are being tested. If the time entered by the user matches one in the database then nothing happens else an error is displayed. What I would like is to perform this same function but using Cold Fusion code which is within a WML application. I have tried ways but get error with the <CFLOOP> tag and also it doesn't help by having to implement the code in WML. Any suggestions?

<%
dim found
found = false
Do while NOT RS.EOF
IF RS(&quot;Times&quot;) = mytime THEN
found = true
end if
RS.MoveNext
Loop

if not found then
errorForm &quot;Not Correct. &quot;
end if
%>

 
Hey Anastasia,

Will this do what you need?

<cfquery name=&quot;Q1&quot;...>
select times from timesTable where times = '#myTime#'
</cfquery>

<cfif q1.recordcount lt 1>
........... Error code here ........
</cfif>

Let me know if it doesn't work,
GJ
 
GunJack.

I am having problems with the WHERE part of the code when I implement this errors are generated within the WML application. When I take this part out no errors occur. I have tried refrencing the variable myTime in different ways but to no success. The error however selects a line number where I have a select statement of another query that I also have on the page. Is it ok to have multipe queries on the wml page or do they have an effect on one another?. Anyway everything works OK when I take out the WHERE statement so their is a problem here?.

 
Hey Anastasia,

I'm not familiar with WML so I'm not sure what you're doing. If it's a Cold Fusion script being executed by Cold Fusion, you can have multiple queries on the same page without problems. If you'll post the error message along with the query it's referencing, it should be more clear what the problem is.

GJ
 
Anastasia is this the same issue you were posting about before? We really need to see the CF, but if this is a WML error based on data CF output... we'll need to see the CF output and the code.

Hope we can help you this time around
 
GunJack Thanks for your help. Your code works fine above. It was not working before so what I have done is change the Date/time format in the database to simple text and took off all input masks.
 
strantheman yes I was having still the same problems with dates and times however I have since changed as mentioned above the format in the database from Date/time to text and took off all input masks thus the code above works fine. However the thing that is giving the problems is still the StartDate/EndDate etc which was my original problem. This still does not work even by changing the formating in the database I seem to have the problem when comparing dates and times that are greater than or less than values.
 
I didn't realize your field was a date/time field. In that case, my code would need to be changed from

select times from timesTable where times = '#myTime#'

to

select times from timesTable where times = #myTime#

When comparing numeric and date/time fields, you don't use single quotes around the values. IRT your comparison problems, are you having trouble inside a SQL statement or inside a CF tag/function?

Let us know if you still have trouble,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top