RE: SV: [PHP] Booking by Date/Time in mySQL
| From: | Jeff Armstrong | Date: | Tue, 20 Mar 2001 15:45:58 +0000 |
| Subject: | RE: SV: [PHP] Booking by Date/Time in mySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44761@lists.php.net to get a copy of this message | ||
One problem is that you are only checking the first booking.
select * from booking where room='room'
gives ALL bookings, and you look like you are just testing
the FIRST one.
why not turn it round and do:
select * from booking where
('$start'>=startdate and '$start'<=enddate) or
('$end'>=startdate and '$end'<=enddate)
This lets mySQL do the test for you.
If it returns a row you already have a booking.
-----Original Message-----
From: Thomas Edison Jr. [mailto:thomasedisonjr@yahoo.com]
Sent: Tuesday, March 20, 2001 11:50 AM
To: Peter Chr. Hansen
Cc: php-general@lists.php.net
Subject: Re: SV: [PHP] Booking by Date/Time in mySQL
Peter,
what do you mean by Newdate between date1 & date2??
the logic i'm using is that i'm checkin if the new
Start Date & End date lies between the old Start Date
& End Date or not. If it does, than entry is denied,
else booking is succesfull. But things are not
running, following is the code i'm using ...
----------
<?php
$db = mysql_connect("localhost","root");
mysql_select_db("nidc_intranet",$db);
$realsdate="$syear"."-"."$smonth"."-"."$stdate";
$realedate="$eyear"."-"."$emonth"."-"."$endate";
$realstime="$shh".":"."$smm"." "."$sttime";
$realetime="$ehh".":"."$emm"." "."$entime";
$result = mysql_query("SELECT * FROM booking where
room='$rooms',$db);
if ($myrow = mysql_fetch_array($result)) {
do {
if ($realsdate>=$myrow[sdate]) &&
($realsdate<=$myrow[edate]) &&
($realedate>=$myrow[sdate]) &&
($realedate<=$myrow[edate]) {
echo "Sorry";
}
else {
$sql = "INSERT INTO booking
(room,sdate,edate,stime,etime,purpose,reserved) VALUES
('$rooms','$realsdate','$realedate','$realstime','$realetime','$purpose','$r
es')";
$result = mysql_query($sql) or Die ("An unexpected
error occured. Please go back and book again.");
echo "<font face=helvetica size=2
color=#140057><b>Thank you! <font
color=#ff0000>$rooms</font>, has been booked from
<font color=#ff0000>$realsdate</font> to <font
color=#ff0000>$realedate</font>.
<br><br>
** Entries will be deleted 2 weeks after the End
Date.
";
}
} while ($myrow = mysql_fetch_array($result));
}
?>
------------
Regards,
T. Edison jr.
--- "Peter Chr. Hansen" <PCH@schilling.dk> wrote:
> Can't you use "
> Newdate between date1 and date2
>
>
> -----Oprindelig meddelelse-----
> Fra: Thomas Edison Jr.
> [mailto:thomasedisonjr@yahoo.com]
> Sendt: 20. marts 2001 12:25
> Til: php-general@lists.php.net
> Emne: [PHP] Booking by Date/Time in mySQL
>
>
> I'm facing this problem.
> I have made a room booking application.
> There is a Start Date & Time and End Date & Time of
> Booking a room.
>
> Problem is that once booked, you can't book a room
> with a date or time that falls between an Already
> booked Date & Time.
>
> For example, if someone's booked a room from 3rd
> March
> to 10th March between 4:00 p.m. to 12:00 p.m. , you
> can't book the same room for the any date between
> 3rd
> March to 10th March and between 4 pm & 12 pm.
>
> How do i do that?
>
> Regards,
> T. Edison jr.
>
>
> =====
> Rahul S. Johari (Director)
> ******************************************
> Abraxas Technologies Inc.
> Homepage : http://www.abraxastech.com
> Email : abraxastech@yahoo.com
> Tel : 91-4546512/4522124
> *******************************************
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-general-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-general-help@lists.php.net
> To contact the list administrators, e-mail:
php-list-admin@lists.php.net
=====
Rahul S. Johari (Director)
******************************************
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : abraxastech@yahoo.com
Tel : 91-4546512/4522124
*******************************************
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net