" . htmlspecialchars($hotel_name['name']) . ""; $sql = " SELECT DISTINCT CONCAT(`date_start`, '|', `date_end`) AS `range` FROM `$table_prices` WHERE `id_hotel` = ".((int)$id_hotel)." ORDER BY `range` "; $res = mysql_query($sql) or die($sql.':'.mysql_error()); for($ranges=array(); ($row = mysql_fetch_assoc($res)); ) $ranges[] = $row['range']; foreach($ranges as $k=>$r) $s .= "". //format_range ($r).""; $s .= "\r\n"; $sql = " SELECT `tr`.`type_room`,`tr`.`id` tid,`pl`.`id` pid, CONCAT(`date_start`, '|', `date_end`) AS `range`, `price` FROM `$table_prices` `pl` LEFT JOIN `$table_rooms` `tr` ON `pl`.`id_room` = `tr`.`id` WHERE `pl`.`id_hotel` = ".((int)$id_hotel)." ORDER BY `tr`.`id`, `range` "; $res = mysql_query($sql) or die( $sql.':'.mysql_error()); $pricelist = array(); while($row = mysql_fetch_assoc($res)) { $room = $row['type_room']; $range = $row['range']; $idr = $row['tid']; //ид комнаты $idp = $row['pid']; //ид цены $pricelist[$idr][$range] = $idp; $rooms[$idr] = $room; $prices[$idp] = $row['price']; /*$room = $row['type_room']; $range = $row['range']; $pricelist[$room][$range] = $row['price'];*/ } foreach($pricelist as $room => $list) { if($rooms[$room]){ $s .= "". htmlspecialchars($rooms[$room]).""; } foreach($ranges as $range){ if(isset($list[$range])) $pric_hotel = isset($prices[$list[$range]]) ? $prices[$list[$range]] : "--"; $s .= "". htmlspecialchars($pric_hotel) . ""; } $s .= "\r\n"; } $s .= "\r\n"; echo $s; /* -- -- Table structure for table `rnt1_hotel` -- CREATE TABLE `rnt1_hotel` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `visible` varchar(2) NOT NULL, `stars` varchar(10) NOT NULL, `place` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; -- -- Dumping data for table `rnt1_hotel` -- INSERT INTO `rnt1_hotel` VALUES (1, 'NARADA', '1', '', 0); INSERT INTO `rnt1_hotel` VALUES (2, 'Ocean Sonic', '1', '', 0); -- -------------------------------------------------------- -- -- Table structure for table `rnt1_room` -- CREATE TABLE `rnt1_room` ( `id` int(11) NOT NULL auto_increment, `type_room` varchar(255) NOT NULL, `id_hotel` int(11) NOT NULL, `visible` varchar(2) NOT NULL, PRIMARY KEY (`id`), KEY `id_hotel` (`id_hotel`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- Dumping data for table `rnt1_room` -- INSERT INTO `rnt1_room` VALUES (1, 'Deluxe Mountain View Room', 1, '1'); INSERT INTO `rnt1_room` VALUES (2, 'Deluxe Garder View Room', 1, '1'); INSERT INTO `rnt1_room` VALUES (3, 'Surerior Ocean View', 1, '1'); INSERT INTO `rnt1_room` VALUES (4, 'Deluxe Ocean View', 1, '1'); -- -------------------------------------------------------- -- -- Table structure for table `rnt1_room_attrs` -- CREATE TABLE `rnt1_room_attrs` ( `id` int(11) NOT NULL auto_increment, `price` int(11) default NULL, `date_start` date default NULL, `date_end` date NOT NULL, `id_room` int(11) default NULL, `id_hotel` int(11) NOT NULL, `visible` varchar(2) default NULL, PRIMARY KEY (`id`), KEY `id_hotel` (`id_hotel`), KEY `id_room` (`id_room`), KEY `id_room_2` (`id_room`) ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ; -- -- Dumping data for table `rnt1_room_attrs` -- INSERT INTO `rnt1_room_attrs` VALUES (1, 90, '2010-12-02', '2011-09-10', 1, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (3, 70, '2010-12-02', '2011-09-10', 2, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (5, 1300, '2010-11-02', '2011-02-25', 3, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (7, 1400, '2010-11-01', '2011-02-26', 4, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (2, NULL, '2010-12-01', '2010-12-10', 2, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (9, 34, '2010-12-02', '2011-09-10', 1, 1, '1'); INSERT INTO `rnt1_room_attrs` VALUES (10, 80, '2010-12-02', '2011-09-10', 2, 1, '1'); */ ?>