Reformat table into three columns
I have a page that builds a table using database to import Rates, Room Type and Season Date.
There are 30 Room Types and therefore the browser displays a large scrolling left to right block of information.
I need to have the table reformated so three lines of 10 Room Types display.
You can see the table displayed at http://www.convictlake.com/reservations/reservation.php
Your suggestions as to how to write the query to properly format the table would be appreciated.
The coding for the entire page is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Convict Lake Resort Reservation System</title>
<link rel="STYLESHEET" href="css/theme.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Convict Lake Resort Reservation System</title>
<!--
function loadRates() {
<?php
require('includes/connection.php');
// if(!isset($_POST['fname'])) {
$sql = 'SELECT R.*, RT.name AS room_type_name, CONCAT(DATE_FORMAT(TF.start_date, \'%m/%d/%y\'), \' to \', DATE_FORMAT(TF.end_date, \'%m/%d/%y\')) AS season FROM rates AS R';
$sql .= ' LEFT JOIN room_type AS RT ON R.room_type_id=RT.room_type_id';
$sql .= ' LEFT JOIN timeframe AS TF ON R.timeframe_id=TF.timeframe_id';
$sql .= ' ORDER BY R.timeframe_id, R.room_type_id';
$result = mysql_query($sql, $DBconnection);
$seasonKey = array();
$roomKey = array();
$table = array();
if($result) {
if(mysql_num_rows($result) > 0) {
echo 'var rates = new Array(' . ");\n";
$season = null;
while(false !== ($data = mysql_fetch_assoc($result))) {
if($season == $data['season']) {
$table[$data['timeframe_id']][$data['room_type_id']] = $data['rate'];
$roomKey[$data['room_type_id']] = $data['room_type_name'];
} else {
$table[$data['timeframe_id']] = array($data['room_type_id'] => $data['rate']);
$seasonKey[$data['timeframe_id']] = $data['season'];
$roomKey[$data['room_type_id']] = $data['room_type_name'];
echo 'rates[' . $data['timeframe_id'] . "] = new Array();\n";
$season = $data['season'];
}
echo 'rates[' . $data['timeframe_id'] . '][' . $data['room_type_id'] . '] = ' . $data['rate']. ";\n";
}
}
}
// }
?>
return rates;
}
function checkTimeFrame(dts) {
<?php
$sql = 'SELECT * FROM timeframe ORDER BY timeframe_type_id DESC';
$result = mysql_query($sql, $DBconnection);
if($result) {
if(mysql_num_rows($result) > 0) {
while(false !== ($timeframe = mysql_fetch_assoc($result))) {
echo "\tif(dts >= Date.UTC(". date('Y',strtotime($timeframe['start_date'])) . ','
. (date('m',strtotime($timeframe['start_date']))-1). ',' .date('d',strtotime($timeframe['start_date'])). ',0,0,0,0) && dts <= Date.UTC('. date('Y',strtotime($timeframe['end_date'])) . ','
. (date('m',strtotime($timeframe['end_date']))-1) . ',' .date('d',strtotime($timeframe['end_date'])). ",0,0,0,0)){\n";
echo "\t\treturn " . $timeframe['timeframe_id'] . ";\n\t}\n";
}
}
}
//strtotime($timeframe['start_date'])*1000
?>
//-->
</head>
<body>
<table align="center" class="pageContent">
<tr>
<!-- styles for the navigation list are in the style sheet -->
<!-- text area in which all of the changing page information goes. -->
<td width="91%" class="infoSection style3">
<!-- title block is 100% width, text is easily changed; style in stylesheet -->
<?php
#############################
## process form submission ##
#############################
#-- form verification done using javascript
$sent = false;
if(isset($_POST['fname'])) {
$first = true;
$error = false;
$errorMessage = '';
$sqlFields = '';
$sqlValues = '';
if(strtotime($_POST['arrivedate']) < strtotime(date('m/d/Y'))){
$error = true;
$errorMessage = 'You cannot reserve a date in the past. Please enter a valid date for arrival and departure.';
}
if(strtotime($_POST['arrivedate']) > strtotime($_POST['departdate'])){
$error = true;
$errorMessage = 'Your departure date must be after your arrival date.';
}
// echo $insert;
if(!$error) {
foreach($_POST AS $name => $value) {
if($name == 'Submit') break;
if($name == 'arrivemonth'||$name=='arriveday'||$name=='arriveyear'||$name=='departmonth'||$name=='departday'||$name=='departyear'||$name=='rt1'||$name=='rt2') {
continue;
}
$name = str_replace('_', ' ', $name);
$formInformation .= '<tr><td align="right"><b>' . $columnsName[$name] . ':</b></td>';
$formInformation .= '<td>' . htmlspecialchars($value) . '</td></tr>';
if($first) {
$first = false;
} else {
$sqlFields .= ',';
$sqlValues .= ',';
}
$sqlFields .= $name;
$sqlValues .= '\'' . mysql_escape_string($value) . '\'';// escape string to prevent hacking
}
$insert = 'INSERT INTO reservations (' . $sqlFields . ') VALUES (' . $sqlValues . ')';
if(mysql_query($insert, $DBconnection)) {
echo '<div class="title">Your reservation has been submitted with the following information.</div><table>' . $formInformation . '</table><br>';
$getID = mysql_query('SELECT LAST_INSERT_ID() AS id FROM reservations', $DBconnection);
if($getID) {
if(mysql_num_rows($getID) > 0) {
if(false !== ($last = mysql_fetch_assoc($getID))) {
$formInformation .= '<tr><td colspan=2><a href="http://www.walkerriverlodge.com/admin/reservation_confirm.php?i=' . $last['id'] . '">Confirm This Reservation</a></td></tr>';
}
}
}
} else {
$error =true;
$errorMessage = 'There was an error in saving your reservation! Please try again, or contact us by phone to make your reservation.';
}
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// $headers .= 'To: Reservations <info@bwalkerriverlodge.com>' . "\r\n";
$headers .= 'From: ' . $_POST['fname'] . ' ' . $_POST['lname'] . ' <' . $_POST['email'] . '>' . "\r\n";
$email = '<table>' . $formInformation . '</table>';
$headers .= 'Cc: [email]ed@talahi.com[/email]' . "\r\n";
// $headers .= 'Bcc: ' . "\r\n";
// if(eregi('@', $_POST['Email'])) {// this makes sure there is an "@" symbol
#mail the form...
// if(mail('jacob@hofothpo.com, [email]jacob86@csufresno.edu[/email]', 'Reservation Form',$email, $headers)) {// for testing purposes
if(mail('Erinn Wells<info@walkerriverlodge.com>', 'Reservation Form',$email, $headers)) {// for testing purposes
$sent = true;
}
// mail('Erinn Wells <info@walkerriverlodge.com>', 'Reservation Form',$email, $headers);
} else {
echo '<div style="font-size: 17px; font-weight: bold; color: #880000; background: #cc7777; border: 1px solid #aa0000;">' . $errorMessage . '</div>';
}
#############################
## end from processing ##
#############################
}
if(!$sent){
echo '<div class="title"><font color="FFFFFF">Rates</font></div>';
# construct rates table
$first = true;
echo '<table class="rates" align="center">';
foreach($table AS $season => $rooms) {
if($first) {
echo '<tr><td class="room">Rooms:</td>';
$firstLine = '<tr><td class="season">' . $seasonKey[$season] . '</td>';
} else {
echo '<tr><td class="season">' . $seasonKey[$season];
echo '</td>';
}
foreach($rooms AS $room => $rate) {
if($first) {
echo '<td class="room">' . $roomKey[$room] . '</td>';
$firstLine .= '<td> $' . $rate . '</td>';
} else {
echo '<td> $' . $rate . '</td>';
}
}
echo '</tr>';
if($first) {
echo $firstLine . '</tr>';
}
$first = false;
}
echo '</table>';
}
?>
</td></tr></table>
</body>
</html>