display todays bookings from mysql mrbs calendar

2019-09-12 13:46发布

I´am as everyone is in the start of something new at this. I am trying to get the right query to display todays booking from a MRBS calendar in the order of time and room fo instance room 1 10 -11, room 2 from 10-11 room1 from 11-14 room 3 from 13-15. I got an array sample for a week from Rowland carson but I want it to display per day and in time order any one got any ideas?? they are very welcome this is going to be set up at a school to show booking per day in the expedition. this is what I have today:

     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条回答
我只想做你的唯一
2楼-- · 2019-09-12 14:11

This SQL will return todays bookings ordered by start_time and 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

If this is not what you are looking for you will need to put more effort into your question. What are the table names and their structures? What format are you expecting the output to be in?

查看更多
登录 后发表回答