<body>
<div style="text-align:center; color:red; font-size:20px; font-weight:bold; margin:5px 0; background-color:#FFC">
รายงานสรุปยอดรายได้ แยกตามประเภทบริการ <?php echo 'วันที่ '.$day.'/'.substr('0'.$month, -2).'/'.$year;?>
</div>
<div align="center" style="background-color:#EAEAEA;width:600px; margin:0 auto;">
<form action="report05.php" method="get">
เลือกวัน:
<select name="day">
<?php for ($i = 1; $i <= 31; $i++):?>
<option value="<?php echo $i;?>"<?php if ($day == $i) echo ' selected="selected"';?>>วันที่ <?php echo $i;?></option>
<?php endfor;?>
</select>
<select name="month">
<option value="01"<?php if ($month=='01') echo ' selected="selected"';?>>มกราคม</option>
<option value="02"<?php if ($month=='02') echo ' selected="selected"';?>>กุมภาพันธ์</option>
<option value="03"<?php if ($month=='03') echo ' selected="selected"';?>>มีนาคม</option>
<option value="04"<?php if ($month=='04') echo ' selected="selected"';?>>เมษายน</option>
<option value="05"<?php if ($month=='05') echo ' selected="selected"';?>>พฤษภาคม</option>
<option value="06"<?php if ($month=='06') echo ' selected="selected"';?>>มิถินายน</option>
<option value="07"<?php if ($month=='07') echo ' selected="selected"';?>>กรกฎาคม</option>
<option value="08"<?php if ($month=='08') echo ' selected="selected"';?>>สิงหาคม</option>
<option value="09"<?php if ($month=='09') echo ' selected="selected"';?>>กันยายน</option>
<option value="10"<?php if ($month=='10') echo ' selected="selected"';?>>ตุลาคม</option>
<option value="11"<?php if ($month=='11') echo ' selected="selected"';?>>พฤษจิกายน</option>
<option value="12"<?php if ($month=='12') echo ' selected="selected"';?>>ธันวาคม</option>
</select>
<select name="year" id="select">
<?php
$sql = "SELECT LEFT (used_day, 4) AS year FROM used GROUP BY LEFT(used_day, 4) DESC";
$query = mysql_query($sql) or die($sql);
while ($row = mysql_fetch_assoc($query))
{
$selected = ($year == $row['year']) ? ' selected="selected"' : '';
echo '<option value="'.$row['year'].'"'.$selected.'>'.$row['year'].'</option>';
}
?>
</select>
<input type="submit" value="แสดงข้อมูล" />
</form>
</div>
<?php
$date = $year.'-'.substr('0'.$month, -2).'-'.$day;
$sql = "SELECT * FROM used WHERE used_day='{$date}'";
$query = mysql_query($sql) or die($sql);
if ( ! mysql_num_rows($query))
exit('<div align="center" style="background-color:white;width:600px; margin:5px auto;">ไม่มีข้อมูล</div><body></html>');
$used_ids = array();
$room_ids = array();
while ($row = mysql_fetch_assoc($query))
{
$used_ids[] = $row['id'];
$room_ids[] = $row['room_id'];
}
$sql1 = "SELECT name, rent FROM room WHERE id IN(".join(',', $room_ids).")";
$query1 = mysql_query($sql1) or die($sql1);
$sql2 = "SELECT food.name AS c1, SUM(used_food.amount) AS c2, food.price AS c3 FROM used_food LEFT JOIN food ON(used_food.food_id=food.id) WHERE used_food.used_id IN(".join(',', $used_ids).") GROUP BY used_food.food_id";
$query2 = mysql_query($sql2) or die($sql2);
$sql3 = "SELECT * FROM used_other WHERE used_id IN(".join(',', $used_ids).")";
$query3 = mysql_query($sql3) or die($sql3);