TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-11-2010, 06:02 PM   #1 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default Not sure how to do this....

Okey dokey....
Got one that am struggling with a bit, not sure if I should use a subquery (never used before) or if I should run 2 queries and process the data in php from the queries....

What I need to do is grab 2 dates from a form (easy enough), query the table to ensure the dates are not overlapping any of the dates in the table..

What I have so far is :-

Code:
select av_bookedid, av_datestart, av_dateend from av_bookings where '2010-06-08' between av_datestart and av_dateend;
obviously the date I put in there would be a var from the form...


and a second query :-

Code:
select av_bookedid, av_datestart, av_dateend from av_bookings where '2010-06-12' between av_datestart and av_dateend;
Should I, would I and if so, how do I use a subquery, I get the feeling I should be, but am a bit lost...




Sample from table
Code:
+-------------+--------------+------------+
| av_bookedid | av_datestart | av_dateend |
+-------------+--------------+------------+
| 2           | 2010-07-15   | 2010-07-17 |
| 4           | 2010-07-15   | 2010-07-17 |
| 3           | 2010-06-26   | 2010-07-04 |
| 3           | 2010-09-11   | 2010-09-18 |
| 3           | 2010-07-23   | 2010-08-01 |
| 2           | 2010-08-20   | 2010-08-24 |
| 3           | 2010-07-15   | 2010-07-22 |
| 4           | 2010-09-17   | 2010-09-20 |
| 2           | 2010-07-19   | 2010-08-02 |
| 1           | 2010-10-08   | 2010-10-11 |
| 5           | 2010-10-08   | 2010-10-10 |
| 1           | 2010-07-23   | 2010-07-25 |
| 4           | 2010-07-23   | 2010-07-25 |
| 5           | 2010-07-23   | 2010-07-25 |
| 5           | 2010-10-22   | 2010-10-24 |
| 2           | 2010-08-07   | 2010-08-14 |
| 5           | 2010-08-28   | 2010-09-04 |
| 5           | 2010-07-16   | 2010-07-19 |
| 3           | 2010-06-19   | 2010-06-26 |
| 4           | 2010-07-02   | 2010-07-04 |
| 1           | 2010-08-16   | 2010-08-23 |
| 4           | 2010-08-28   | 2010-09-04 |
| 4           | 2010-07-31   | 2010-08-02 |
| 1           | 2010-06-17   | 2010-06-22 |
| 1           | 2010-07-31   | 2010-08-07 |
| 5           | 2010-06-30   | 2010-07-04 |
| 2           | 2010-08-16   | 2010-08-20 |
| 4           | 2010-07-26   | 2010-07-30 |
| 5           | 2010-07-26   | 2010-07-30 |
| 3           | 2010-08-01   | 2010-09-01 |
| 3           | 2010-07-10   | 2010-07-14 |
| 5           | 2010-08-13   | 2010-08-15 |
| 5           | 2010-08-19   | 2010-08-21 |
| 2           | 2010-10-23   | 2010-10-27 |
| 4           | 2010-08-04   | 2010-08-11 |
| 5           | 2010-08-09   | 2010-08-12 |
| 3           | 2010-12-27   | 2011-01-02 |
| 5           | 2010-12-27   | 2011-01-02 |
| 5           | 2010-09-17   | 2010-09-21 |
| 1           | 2010-07-16   | 2010-07-18 |
| 5           | 2010-10-15   | 2010-10-17 |
| 5           | 2010-07-31   | 2010-08-07 |
| 1           | 2010-07-08   | 2010-07-15 |
| 4           | 2010-08-25   | 2010-08-28 |
| 2           | 2010-09-01   | 2010-09-05 |
| 1           | 2010-06-22   | 2010-06-25 |
| 1           | 2010-08-07   | 2010-08-10 |
| 1           | 2010-06-26   | 2010-07-03 |
| 3           | 2010-06-12   | 2010-06-14 |
| 1           | 2010-07-18   | 2010-07-21 |
| 2           | 2010-06-27   | 2010-07-02 |
| 4           | 2010-06-27   | 2010-07-02 |
| 3           | 2010-06-25   | 2010-05-29 |
| 2           | 2010-06-19   | 2010-06-21 |
| 4           | 2010-06-19   | 2010-06-21 |
| 4           | 2010-07-12   | 2010-07-15 |
| 5           | 2010-06-18   | 2010-06-20 |
| 2           | 2010-07-02   | 2010-07-07 |
| 4           | 2010-09-25   | 2010-09-26 |
+-------------+--------------+------------+
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Old 06-13-2010, 01:30 PM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

Got it sorted out and thought would post the sql in case anyone else comes across this sort of issue...

Code:
$sql = "select av_bookedid as 'accom_unavail', av_datestart , av_dateend from av_bookings where  av_confirmed !=0 
	AND 
	(av_datestart < '$av_reqdatestart' AND av_dateend >= '$av_reqdatestart') 
	AND 
	(av_datestart <= '$av_reqdateend' AND av_dateend >= '$av_reqdateend') 
	OR 
	(av_datestart >= '$av_reqdatestart'  AND av_dateend <= '$av_reqdateend')";
__________________
Thanks... Simon

Sex, Drugs & Linux Rules

Last edited by maeltar : 06-13-2010 at 01:30 PM. Reason: bbcode added
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:14 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design