Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:18:19+00:00 2026-05-28T17:18:19+00:00

I have a php MySql booking calendar, which shows whether the room is booked

  • 0

I have a php MySql booking calendar, which shows whether the room is booked or not on a date basis. The problem is, it shows the wrong info. For example, if I book 5-6 it should have marked the 5th red, meaning it was booked on 5th. It shows 6th but by 6, 12:00:00 the room will be free. Another example: If I book 23-25 it shows 24, 25 as booked, but it should show 23-25, dont know where the problem is.

Here is the code:

  function getAllRooms($date,$month,$year)
{
    global $db;
    $where = ' ';
    if ($_GET['room_type'] != '') {
        $where .= " HAVING room_type = '".$_GET['room_type']."'";
    }

    $sql = "SELECT room_type 
            FROM 
                room 
            GROUP BY 
                room_type 
            $where
            ";
    /*echo $sql;
    exit;*/
    $result = $db->Execute($sql);;
    $room = '';
    while (!$result->EOF) {
        $qs     = '?room_type='.$result->fields('room_type').'&month='.$month.'&year='.$year;
        $total  = get_total_rooms_by_type($result->fields('room_type'),$date,$month,$year);
        $room   .=
        '<div class="'.$result->fields('room_type').'"> 

            <a href="'.BASE_URL.'room_detail.php'.$qs.'">
                '.$result->fields('room_type').' ('.$total.')
            </a>
        </div>';
        $result->MoveNext();
    }
    $result->Close;
    return $room;
}
function get_total_rooms_by_type($room_type,$date,$month,$year)
{
    global $db;
    $_newdate   = $year.'-'.$month.'-'.$date;
    $sql            = "SELECT room_id FROM room where room_type = '$room_type' ";
    $room_results   = $db->Execute($sql);
    $room_ids       = array();
    while (!$room_results->EOF) {
        $room_ids[] = $room_results->fields('room_id');
        $room_results->MoveNext();
    }
    $room_results_str = implode(',',$room_ids);
    $where = ' where 1 = 1 ';
    $available = 1;
    if ($_GET['booking_status'] == '1') {
        $where .= ' and (booking_status = 1 or booking_status = 2)';
        $available = 0;
    } else if ($_GET['booking_status'] == '2') {
        $where .= ' and (booking_status = 2)';
        $available = 0;
    } 
    $sql = "select count(room_id) from bookings 
            $where 
                and checkin <= '$_newdate'
                and '$_newdate' <= checkout
                and room_id in ($room_results_str)
            ";
    if ($available == 0) {
        return $db->GetOne($sql);

    } else {
        return count($room_ids) - $db->GetOne($sql);
    }


}
function draw_calendar_room($month,$year){

    /* draw table */
    $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';

    /* table headings */
    $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';


    /* days and weeks vars now ... */
    $running_day = date('w',mktime(0,0,0,$month,1,$year));
    $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
    $days_in_this_week = 1;
    $day_counter = 0;
    $dates_array = array();

    /* row for week one */
    $calendar.= '<tr class="calendar-row">';

    /* print "blank" days until the first of the current week */
    for($x = 0; $x < $running_day; $x++):
        $calendar.= '<td class="calendar-day-np">&nbsp;</td>';
        $days_in_this_week++;
    endfor;

    /* keep going with days.... */
    for($list_day = 1; $list_day <= $days_in_month; $list_day++):
        $calendar.= '<td class="calendar-day">';;

            $calendar.= '<div class="day-number" style=" padding:5px 5px 45px;background-color:'.getRoomColor($list_day,$month,$year).'">'.$list_day.'</div>';

            /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !!  IF MATCHES FOUND, PRINT THEM !! **/


        $calendar.= '</td>';
        if($running_day == 6):
            $calendar.= '</tr>';
            if(($day_counter+1) != $days_in_month):
                $calendar.= '<tr class="calendar-row">';
            endif;
            $running_day = -1;
            $days_in_this_week = 0;
        endif;
        $days_in_this_week++; $running_day++; $day_counter++;
    endfor;

    /* finish the rest of the days in the week */
    if($days_in_this_week < 8):
        for($x = 1; $x <= (8 - $days_in_this_week); $x++):
            $calendar.= '<td class="calendar-day-np">&nbsp;</td>';
        endfor;
    endif;

    /* final row */
    $calendar.= '</tr>';

    /* end the table */
    $calendar.= '</table>';

    /* all done, return result */
    return $calendar;
}
function getRoomColor($date,$month,$year)
{
    global $db;
    $where = ' ';
    if ($_GET['room_id'] != '') {
        $room_id    = $_GET['room_id'];

    } else {
        $sql = "SELECT room_id
                        FROM 
                            room 
                        WHERE
                            room_type = '".$_GET['room_type']."' order by room_number asc
                        ";
        $room_id = $db->GetOne($sql);;
    }
    $_newdate = "$year-$month-$date";
    $sql = "SELECT booking_status
            FROM 
                bookings 
            where 
                checkin <= '$_newdate'
                and 
                '$_newdate' <= checkout
                and 
                room_id = '$room_id'
            ";
    /*echo $sql;
    exit;*/
    $result = $db->GetOne($sql);;
    if ($result == 1) {
        return '#FF0';
    } else if ($result == 2) {
        return '#F00';
    } else {
        return '#64C733';
    }

} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:18:20+00:00Added an answer on May 28, 2026 at 5:18 pm

    it was actually issue of time mismatch. In db I set date time as checkin and checkout but my checking sql retrieving data with date there were no time consideration.

    now added:

    $_newdate   = $year.'-'.$month.'-'.$date . " " . "12:00:00";
    

    is working like a charm. !!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have php mysql calneder for my hotel room booking system. but it shows
I have a PHP/MySQL date formatting problem. Here, i create the date variables: $checkDate
I have a PHP/MySQL driven site, which I have not maintained for the past
I have PHP code which connects to MySql and encodes data to JSON. Later
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
i work with php/Mysql i have table with two cols (date , cash) with
I have a PHP MySQL application which has a modular design. There are about
I am using PHP and Mysql I have PHP script in which I rollback
We have an PHP/MySQL application where the users can create their own databases, which
I have a mysql/php query which searches through a database and returns matches based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.