显示今天的mysql mrbs日历预订

时间:2012-03-20 21:36:18

标签: php mysql calendar

我和每个人都处于新事物的开端。 我正在尝试从MRBS日历中按照时间和房间的顺序显示今天预订的正确查询实例室1 10 -11,房间2从10-11房间1从11-14房间3从13-15。 我从罗兰卡森那里得到了一个星期的阵列样本,但是我希望它每天都按时间顺序显示任何人有任何想法吗?他们非常欢迎这将在学校设立,以便在探险中每天预订。 这就是我今天所拥有的:

     session_start();
$php_session_id = session_id();

$this_page = basename($_SERVER['PHP_SELF']);
if ($_SESSION[ThisPage] == $this_page)
{

}

define("ONE_DAY", (60*60*24));

$nowArray = getdate();

if ( $_POST[show_calendar] != "" ) // form submitted so capture data from it
{
    switch ( $_POST[show_calendar] )
    {
        case "chosen":
            if ( !checkdate($_POST['month'], $_POST['mday'], $_POST['year']))
            {
                $day = $nowArray['mday'];
                $month = $nowArray['mon'];
                $year = $nowArray['year'];
            }
            else
            {
                $day = $_POST['mday'];
                $month = $_POST['month'];
                $year = $_POST['year'];
            }
            break;


    }

}
else // first pass, form not submitted
{
    $day = $nowArray['mday'];
    $month = $nowArray['mon'];
    $year = $nowArray['year'];
}

$startTimestamp = mktime (0, 0, 0, $month, $day, $year);
$theDateArray = getdate($startTimestamp);

$theWeekday = $theDateArray['wday'];
if ($theWeekday > 1)
{
    $startTimestamp = $startTimestamp - ($theWeekday * ONE_DAY);
    $theDateArray = getdate($startTimestamp);
}

$theTimestamp = $startTimestamp;

$startingDateArray = getdate($startTimestamp);

$startYear = $theDateArray['year'];

$dispTimestamp = $startTimestamp;

//connect to database
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass)
    or die(mysql_error());
mysql_select_db($booking_db, $conn)  or die(mysql_error());

$get_entries = "select timestamp
    from $bookings
    order by timestamp desc
    limit 1
    "
    ;
$entries_result = mysql_query($get_entries) or die(mysql_error());
$data_row = mysql_fetch_object($entries_result);
$last_changed = $data_row->timestamp;

$get_rooms = "select *
    from $rooms
    order by id
    "
    ;
$rooms_result = mysql_query($get_rooms) or die(mysql_error());
$n_rooms = mysql_num_rows($rooms_result);
$n_cols = $n_rooms + 1;

$booking_block = "<TABLE align=center BORDER=1 CELLPADDING=5>\n";
$booking_block .= "<tr><td colspan=".$n_cols.">";
$booking_block .= "Room bookings for today ";
$booking_block .= $startingDateArray['mday']." ";
$booking_block .= $startingDateArray['month']." ";
$booking_block .= $startingDateArray['year']." ";
$booking_block .= "(Last change to any booking was made ";
$booking_block .= $last_changed;
$booking_block .= ")</td></tr>\n";
$booking_block .= "<tr><td align=right>".$startYear."</td>\n";

while ($rooms = mysql_fetch_array($rooms_result, MYSQL_ASSOC))
{
    $booking_block .= "<td>";
    $booking_block .= $rooms['room_name'];
    $booking_block .= "</td>";
}
$booking_block .= "</tr>\n";

for ($day_number = 0; $day_number <= 6; $day_number++)
{
    $booking_block .= "<tr>\n";
    $booking_block .= "<td align=right valign=top>";
    $endOfDay = $theTimestamp + ONE_DAY;
    $theDateArray = getdate($theTimestamp);
    if ($theDateArray['year'] != $startYear)
    {
        $startYear = $theDateArray['year'];
        $booking_block .= $startYear."<br>";
    }
    $booking_block .= date("D d M", $theTimestamp)."</td>\n";

    for ($room_number = 1; $room_number <= $n_rooms; $room_number++)
    {
        $get_bookings = "select *
            from $bookings
            where start_time >= $theTimestamp
            and start_time <= $endOfDay
            and room_id = $room_number
            order by start_time
            "
            ;
        $bookings_result = mysql_query($get_bookings) or die(mysql_error());
        $booking_block .= "<td valign=top>";
        if (mysql_num_rows($bookings_result) > 0)
        {
            while ($booking_entry = mysql_fetch_array($bookings_result, MYSQL_ASSOC))
            {
                $booking_block .= date("H:i", $booking_entry['start_time']);
                $booking_block .= "-";
                $booking_block .= date("H:i", $booking_entry['end_time']);
                $booking_block .= " ";
                $booking_block .= $booking_entry['name'];
                $booking_block .= "<br>\n";
            }
        }
        else
        {
            $booking_block .= "<br>";
        }
        $booking_block .= "</td>";
    }
    $booking_block .= "</tr>\n";
    $theTimestamp = $theTimestamp + ONE_DAY;
}

$booking_block .= "<tr><td colspan=".$n_cols." align=right>";
$booking_block .= "This web page rendered on ";
$booking_block .= $nowArray['mday']." ";
$booking_block .= $nowArray['month']." ";
$booking_block .= $nowArray['year']." ";

$booking_block .= "</table>\n";

// Close the database connection
mysql_close($conn);

?>

<html>
<head>
    <meta http-equiv="Content-Style-Type" content="text/css">
    <link type="text/css" rel="stylesheet" href="q_style.css">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title><?php echo "Room bookings for week of ".$startingDateArray['mday']." ".$startingDateArray['month']." ".$startingDateArray['year'] ?></title>
<head>
<body>

<?php include("page_header.php") ?>

<hr>

<table border=0 cellpadding=1 width="100%">
    <tr>
        <td align=right>&nbsp;</td>
    </tr>
</table>

<table align=center BORDER=0 CELLPADDING=5 width="100%">
    <tr>
        <td>
            <?php echo $booking_block; ?>     </td>
    </tr>
</table>

<table border=0 cellpadding=1 width="100%">
    <tr>
        <td>&nbsp;</td>
    </tr>
</table>

<hr>

1 个答案:

答案 0 :(得分:0)

此SQL将返回今天由start_time和room_id -

订购的预订
SELECT *
FROM $bookings
WHERE start_time >= UNIX_TIMESTAMP(CURRENT_DATE)
AND start_time < UNIX_TIMESTAMP(CURRENT_DATE + INTERVAL 1 DAY)
ORDER BY start_time, room_id

如果这不是你想要的,你需要在你的问题上投入更多精力。表名及其结构是什么?您希望输出采用什么格式?