•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 456,541 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,313 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser: Programming Forums
Views: 1611 | Replies: 2
![]() |
•
•
Join Date: Apr 2007
Posts: 28
Reputation:
Rep Power: 2
Solved Threads: 0
Hi,
I have a calendar w/data stored in SQL Server. People can reserve multiple dates for an event. Before a reservation is confirmed, I want to be able to see if the dates have already been reserved.
I first query the dates for the unconfirmed reservation. I then want to query the database for all other records matching those dates. However, when I reference the dates from my first query, my output only shows one of the dates. For example:
<cfquery name = "newreserve" datasource = "mydata"
select reservedate
from mytable
where url.id = reserveid
</cfquery>
<cfoutput query = "newreserve">
<cfquery name = "duplicates" datasource = "mydata">
select *
from mytable
where reservedate = #newreserve.reservedate#
</cfquery>
</cfoutput>
<cfoutput query = "duplicates">
#reservedate#
</cfoutput>
I know I'm doing something very wrong, but don't know what it is.
Thank you!
I have a calendar w/data stored in SQL Server. People can reserve multiple dates for an event. Before a reservation is confirmed, I want to be able to see if the dates have already been reserved.
I first query the dates for the unconfirmed reservation. I then want to query the database for all other records matching those dates. However, when I reference the dates from my first query, my output only shows one of the dates. For example:
<cfquery name = "newreserve" datasource = "mydata"
select reservedate
from mytable
where url.id = reserveid
</cfquery>
<cfoutput query = "newreserve">
<cfquery name = "duplicates" datasource = "mydata">
select *
from mytable
where reservedate = #newreserve.reservedate#
</cfquery>
</cfoutput>
<cfoutput query = "duplicates">
#reservedate#
</cfoutput>
I know I'm doing something very wrong, but don't know what it is.
Thank you!
•
•
Join Date: Jul 2005
Location: Downingtown
Posts: 58
Reputation:
Rep Power: 4
Solved Threads: 3
From what I can gleam from your sql, I am not even sure that you know that you want this code to work. The name reserveid screams primary key to me, and you shouldn't have to loop over the results of a query that should only give you one record in the first place. I will just tell you the problem with your current code since your db schema seems a little wacky. Your problem is that you seem to have the code that handles each iteration of the loop over "newreserve" AFTER your loop ends. Hence your code outputting reservedate only has the data for the last iteration of the first loop. I believe this is more what you are looking for.
PS: Take out the Select * from your cfqueries. Makes the footprint of this code bigger.
<cfquery name = "newreserve" datasource = "mydata"
select reservedate
from mytable
where reserveid = #URL.id#
</cfquery>
<cfloop query = "newreserve">
<cfquery name = "duplicates" datasource = "mydata">
select *
from mytable
where reservedate = #newreserve.reservedate#
</cfquery>
<cfoutput>Reserve Date: #newreserve.reservedate#<br /></cfoutput>
<cfoutput query="duplicates">
#duplicates.reservedate#
</cfoutput>
</cfloop>PS: Take out the Select * from your cfqueries. Makes the footprint of this code bigger.
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I am not sure of the logic of what you are trying to do. You indicate below there is an url.id variable, which indicates you have inserted the date. If this is the case, it should be encased as and should come after "reserveid" in your query - like where
That said, this to me indicates you have already written the request into the database. As only one date can be associated with on record (I assume), then you only have one date associated with the first query. I for one wouldn't write the data into the database until I had already checked for duplicates.
Assuming you have written the data into the database for some reason, now you can check for this same date in other records - however, from what you have written, you will always at the least find the record you just inserted (when in fact there may be no duplicates). To avoid this, I would try the following for the second query (I can't remember if sql server is , so you would have to check the sql equivalent for "not equals"):
Finally, with sql server, a date value can be inserted as a timestamp? So, the time aspect of the record may make the date aspect of the record unique. You really should be searching for and inserting date values using the function, and when you insert the record, make the timestamp aspect set to 00:00:00. Ideally, you should use a datatype in the database that is date only.
Hope this helps.
D
#url.id#
"reserveid = #url.id#"
That said, this to me indicates you have already written the request into the database. As only one date can be associated with on record (I assume), then you only have one date associated with the first query. I for one wouldn't write the data into the database until I had already checked for duplicates.
Assuming you have written the data into the database for some reason, now you can check for this same date in other records - however, from what you have written, you will always at the least find the record you just inserted (when in fact there may be no duplicates). To avoid this, I would try the following for the second query (I can't remember if sql server is
<> or !=
<cfquery name = "duplicates" datasource = "mydata"> select * from mytable where reservedate = #newreserve.reservedate# and reserveid != #url.id# </cfquery>
Finally, with sql server, a date value can be inserted as a timestamp? So, the time aspect of the record may make the date aspect of the record unique. You really should be searching for and inserting date values using the
#createODBCdate(reservedate)#
Hope this helps.
D
•
•
•
•
Hi,
I have a calendar w/data stored in SQL Server. People can reserve multiple dates for an event. Before a reservation is confirmed, I want to be able to see if the dates have already been reserved.
I first query the dates for the unconfirmed reservation. I then want to query the database for all other records matching those dates. However, when I reference the dates from my first query, my output only shows one of the dates. For example:
<cfquery name = "newreserve" datasource = "mydata"
select reservedate
from mytable
where url.id = reserveid
</cfquery>
<cfoutput query = "newreserve">
<cfquery name = "duplicates" datasource = "mydata">
select *
from mytable
where reservedate = #newreserve.reservedate#
</cfquery>
</cfoutput>
<cfoutput query = "duplicates">
#reservedate#
</cfoutput>
I know I'm doing something very wrong, but don't know what it is.
Thank you!
![]() |
•
•
•
•
•
•
•
•
DaniWeb ColdFusion Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- please help me!!been trying to trace where ive gone wrong!!! (C)
- plz help(Airline Reservation System) (C++)
- PHP Confirm Delete (PHP)
Other Threads in the ColdFusion Forum
- Previous Thread: <CFMail issure
- Next Thread: Starting With ColdFusion


Linear Mode