显示月表中mysql的值

时间:2015-03-30 13:56:59

标签: php mysql days

我需要相应地显示mysql表中的值到月中的某一天。 我使用下面的代码显示月份1-31但是如何将值插入当天的确切单元格?如何实现这一目标?

<?php
$conn=mysql_connect("....",".....","...");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("roomsbooking")) {
echo "Unable to select roomsbooking: " . mysql_error();
exit;
}
// get All the rooms with id_item = 1 (is room 201) and MAY.
$sql="SELECT * FROM bookings WHERE id_item = '1' AND month(the_date)='5'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
$room201 .= '<td>'.$row['id_state'].'</td>';
}
// get All the rooms with id_item = 2 (is room 104) and MAY.
$sql2 = "SELECT * FROM bookings WHERE id_item = '2' AND month(the_date)='5'";
$result2 = mysql_query($sql2);
while ($row = mysql_fetch_assoc($result2))
{
$Room104 .= '<td>'.$row['id_state'].'</td>';
}
echo '
<table class="">  
<tfoot>
<th>Days</th>';
 for($i = 1; $i <= 31; $i++) //statement to display month days.
{
echo "<th>" . $i . "</th>";
} 
echo '</tfoot>
<tbody>
<tr>
<td><b>Room201:</b></td>'.$room201 .'
</tr>
<tr>
<td><b>Room104:</b></td>'.$Room104 .'
</tr>
</tbody>
</table>';
mysql_free_result($result);
?>

Present result Desirable

1 个答案:

答案 0 :(得分:0)

根据您的代码。请注意,有一些非常严肃的事情应该做,我没有解决,但我认为这会让你开始:http://pastebin.com/Fvs8A49n