User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Apr 2007
Posts: 28
Reputation: lafalot is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
lafalot lafalot is offline Offline
Light Poster

confirm reservation

  #1  
Oct 12th, 2007
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: Downingtown
Posts: 58
Reputation: hinde is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
hinde hinde is offline Offline
Junior Poster in Training

Re: confirm reservation

  #2  
Oct 20th, 2007
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.

<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.
Reply With Quote  
Join Date: Oct 2007
Posts: 1
Reputation: hyde11 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hyde11 hyde11 is offline Offline
Newbie Poster

Re: confirm reservation

  #3  
Oct 22nd, 2007
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
"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 , so you would have to check the sql equivalent for "not equals"):

<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)#
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

Originally Posted by lafalot View Post
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!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ColdFusion Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 4:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC