【问题标题】:Display values from mysql in month table在月表中显示来自 mysql 的值
【发布时间】:2015-03-30 13:56:58
【问题描述】:

我需要根据月份的日期显示 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);
?>

【问题讨论】:

  • 那么,数据库中有当天的项目吗?你只是说“选择*”所以我们看不到那个结构。我假设您希望将此项的值(可能称为“day”)与循环中的 $i 变量进行比较,并在它们匹配时打印一些内容。 :)
  • 是的。该表有 6 列(cust_id、id_item、surname、id_state、id_booking、the_date)。“id_state”采用两个不同的值“1”或“4”。请参阅上面的图片。第一张图像连续回显所有值,但我需要在一个月的确切日期回显它们。

标签: php mysql days


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多