mam mały problem z pętlą.
Napisałem kod:
<?php $do_dd = '14'; $do_mm = '02'; $do_rr = '2009'; $z_dd = '15'; $z_mm = '02'; $z_rr = '2009'; for($i=1;$i<4;$i++){ $zapytanie = "SELECT * FROM pokoj_".$i; if(($do_dd !== $pok['do_dd']) && ($z_dd !== $pok['z_dd']) && ($do_mm !== $pok['do_mm']) or ($z_mm !== $pok['z_mm'])){ } else { }}} ?>
Baza Danych:
Kod
--
-- Struktura tabeli dla `pokoj_1`
--
CREATE TABLE `pokoj_1` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_1`
--
INSERT INTO `pokoj_1` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES(1, '11', '02', '2009', '13', '02', '2009'), (2, '14', '02', '2009', '15', '02', '2009');
-- --------------------------------------------------------
--
-- Struktura tabeli dla `pokoj_2`
--
CREATE TABLE `pokoj_2` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_2`
--
INSERT INTO `pokoj_2` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES (1, '11', '08', '2009', '13', '08', '2009'), (2, '14', '08', '2009', '15', '08', '2009');
-- --------------------------------------------------------
--
-- Struktura tabeli dla `pokoj_3`
--
CREATE TABLE `pokoj_3` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_3`
--
INSERT INTO `pokoj_3` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES (1, '11', '02', '2009', '13', '02', '2009'), (2, '14', '02', '2009', '15', '02', '2009');
-- Struktura tabeli dla `pokoj_1`
--
CREATE TABLE `pokoj_1` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_1`
--
INSERT INTO `pokoj_1` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES(1, '11', '02', '2009', '13', '02', '2009'), (2, '14', '02', '2009', '15', '02', '2009');
-- --------------------------------------------------------
--
-- Struktura tabeli dla `pokoj_2`
--
CREATE TABLE `pokoj_2` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_2`
--
INSERT INTO `pokoj_2` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES (1, '11', '08', '2009', '13', '08', '2009'), (2, '14', '08', '2009', '15', '08', '2009');
-- --------------------------------------------------------
--
-- Struktura tabeli dla `pokoj_3`
--
CREATE TABLE `pokoj_3` (
`id` int(11) NOT NULL auto_increment,
`do_dd` text,
`do_mm` text,
`do_rr` text,
`z_dd` text,
`z_mm` text,
`z_rr` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=3;
--
-- Zrzut danych tabeli `pokoj_3`
--
INSERT INTO `pokoj_3` (`id`, `do_dd`, `do_mm`, `do_rr`, `z_dd`, `z_mm`, `z_rr`) VALUES (1, '11', '02', '2009', '13', '02', '2009'), (2, '14', '02', '2009', '15', '02', '2009');
Pętla wyświetla mi:
Kod
Rezerwacja pokoju 1
Pokój 1 zajęty
Rezerwacja pokoju 2
Rezerwacja pokoju 2
Rezerwacja pokoju 3
Pokój 3 zajęty
Pokój 1 zajęty
Rezerwacja pokoju 2
Rezerwacja pokoju 2
Rezerwacja pokoju 3
Pokój 3 zajęty
Chodzi mi o to że jeśli dane istnieją w tabeli obojętnie pod jakim ID to żeby nie wyświetlało mi tyle razy ile jest ID w bazie tylko raz o to co jest w zapytaniu:
Kod
Pokój 1 zajęty
Rezerwacja pokoju 2
Pokój 3 zajęty
Rezerwacja pokoju 2
Pokój 3 zajęty