Created
July 3, 2012 19:52
-
-
Save md2perpe/3042512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['sendRequest'])) | |
{ | |
//Jag tar emot start-date och end-date via ett formular. | |
//Jag kor strtotime pa varderna for att omvandla dem till Unix timestamp | |
$startDate = strtotime($_POST['startDate']); | |
$endDate = strtotime($_POST['endDate']); | |
//Uppbyggnad av tabell | |
echo '<table width="100%" border="1">'; | |
echo '<tr>'; | |
echo '<td><b>Date</b></td>'; | |
echo '<td><b>Privates</b></td>'; | |
echo '<td><b>Dorms</b></td>'; | |
echo '</tr>'; | |
//For-loopen loopar igenom antalet dagar. | |
//Langst ner i for-loopen far $startDate ett nytt varde ($startDate += 86400). | |
for( ; $startDate <= $endDate; $startDate += 86400) | |
{ | |
//Borjar med att rita upp innehallet i tabellen och formatera Unix timestamp till e.g. Jun 1 | |
echo '<tr>'; | |
echo '<td>'.date("M j", $startDate).'</td>'; | |
//Borjar med att hamta information ifran databasen. | |
$sql = " | |
SELECT | |
SUM(r1.roomType='private') AS privatesCount, | |
SUM(r1.roomType='dorm') AS dormsCount | |
FROM reservations r1 | |
INNER JOIN reservations r2 | |
USING (id_of_room) | |
WHERE r1.end_date={$startDate} AND r2.start_date={$startDate} | |
AND r1.roomType IN ('private', 'dorm') | |
AND r1.id_of_guest <> r2.id_of_guest | |
"; | |
$result = mysql_query($sql) or die(mysql_error()); | |
$row = mysql_fetch_array($result); | |
//Varderna skrivs ut i tabellen | |
echo '<td>'.$row['privatesCount'].'</td>'; | |
echo '<td>'.$row['dormsCount'].'</td>'; | |
echo '</tr>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment