i'm trying to develop a booking system for hotel. in my search form i've two datepicker (date departure and date arrival), and the destination. I've a problem with date, in my database i've two tables "prices" and "season" that can be joined with jointure via the id of season .
structure of tables:
CREATE TABLE IF NOT EXISTS `prices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`prix_single` varchar(255) NOT NULL,
`prix_double` varchar(255) NOT NULL,
`prix_triple` varchar(255) NOT NULL,
`idseason` varchar(255) NOT NULL,
`idhotel` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=41 ;
CREATE TABLE IF NOT EXISTS `season` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`begin_date` varchar(255) NOT NULL,
`end_date` varchar(255) NOT NULL,
`idhotel` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)
for exemple for season a i've the periode of 1 January to 28 of February (100 $ the night per person) 1 March to 28 of April (120 $ the night per person)
if my client select the period [26 February to 3 March] how can I calculate it with SQL? i've tried this:
SELECT *
FROM season, prices
WHERE season.id=prices.season
and (season.begin_season BETWEEN 2012/02/26 AND 2012/03/03 OR season.fin_season BETWEEN 2012/02/26 AND 2012/03/03)
it didn't works for me, it's return to me empty result, i've in my Database two seasons
id begin_season end_season idhotel
32 10/07/2012 28/09/2012 52
35 29/09/2012 29/10/2012 52
How can i do this? Thanks a lot!
Edit: i've changed my tables and my query like this:
CREATE TABLE IF NOT EXISTS `season` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`begin_season` date NOT NULL,
`end_season` date NOT NULL,
`idhotel` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `season` (`id`, `begin_season`, `end_season`, `idhotel`) VALUES
(32, '2012-08-09', '2012-09-09', '52'),
(35, '2012-09-10', '2012-10-30', '52');
CREATE TABLE IF NOT EXISTS `prices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`price_single` varchar(255) NOT NULL,
`price_double` varchar(255) NOT NULL,
`price_triple` varchar(255) NOT NULL,
`idseason` varchar(255) NOT NULL,
`idhotel` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `prices` (`id`, `price_single`, `price_double`, `price_triple`, `idseason`, `idhotel`) VALUES
(31, '10', '20', '30', 32, 52),
(32, '20', '40', '60', 35, 52),
SELECT * FROM season, prices WHERE season.id=prices.idseason and (season.begin_season BETWEEN '2012-09-30' AND '2012-10-27' OR season.end_season BETWEEN '2012-09-30' AND '2012-10-27')
My result is empty.