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 7732079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:38:31+00:00 2026-06-01T06:38:31+00:00

Ok I am making a booking system in PHP / Mysql and so far

  • 0

Ok I am making a booking system in PHP / Mysql and so far I just have a basic form made to test inserting data but I want to improve it to only show time slots that are avalible.

I have used the following so far after asking earlier;

function mysql_fetch_rowsarr($result, $numass=MYSQL_BOTH) {
  $i=0;
  $keys=array_keys(mysql_fetch_array($result, $numass));
  mysql_data_seek($result, 0);
    while ($row = mysql_fetch_array($result, $numass)) {
      foreach ($keys as $speckey) {
        $got[$i][$speckey]=$row[$speckey];
      }
    $i++;
    }
  return $got;
}


$conn = mysql_connect($host,$user,$pass);
if (!$conn) {
    die('Could not connect: ' . mysql_error());
};

//Get rodays date
date_default_timezone_set('GMT');
$check_time = date("Y-m-d"); 

mysql_select_db($db, $conn);
mysql_set_charset('utf8',$conn);

$booking_check = mysql_query("SELECT * FROM Booking WHERE Booking_Start LIKE '%$check_time%'");

//if no bookings just echo the entire form but if there is do the else
if (mysql_num_rows($booking_check) == 0) {
    echo '
        <select name="time" id="time">
            <option value="0" selected>(Please Select:)</option>
            <option value="00:00">00:00 - 00:55</option>
            <option value="01:00">01:00 - 01:55</option>
            <option value="02:00">02:00 - 02:55</option>
            <option value="03:00">03:00 - 03:55</option>
            <option value="04:00">04:00 - 04:55</option>
            <option value="05:00">05:00 - 05:55</option>
            <option value="06:00">06:00 - 06:55</option>
            <option value="07:00">07:00 - 07:55</option>
            <option value="08:00">08:00 - 08:55</option>
            <option value="09:00">09:00 - 09:55</option>
            <option value="10:00">10:00 - 10:55</option>
            <option value="11:00">11:00 - 11:55</option>
            <option value="12:00">12:00 - 12:55</option>
            <option value="13:00">13:00 - 13:55</option>
            <option value="14:00">14:00 - 14:55</option>
            <option value="15:00">15:00 - 15:55</option>
            <option value="16:00">16:00 - 16:55</option>
            <option value="17:00">17:00 - 17:55</option>
            <option value="18:00">18:00 - 18:55</option>
            <option value="19:00">19:00 - 19:55</option>
            <option value="20:00">20:00 - 20:55</option>
            <option value="21:00">21:00 - 21:55</option>
            <option value="22:00">22:00 - 22:55</option>
            <option value="23:00">23:00 - 23:55</option>
        </select>
    ';
} else {


    //counter set to 23 because of 0
    $counter = 23;
    $i = 0;

    $booked_times = mysql_fetch_rowsarr($booking_check);
    $num_booked = mysql_num_rows($booking_check);

    echo date("H", strtotime($booked_times[0]['Booking_Start']));
    echo date("H", strtotime($booked_times[1]['Booking_Start']));

    echo "<select name='time' id='time'>";
    echo "<option value='0' selected>(Please Select:)</option>"; 
    while($i<=$counter) {
        //$H is used to compare if the hour slot is booked this adds a 0 to the front of the varible if under 10 for the 24H time format.
        if ($i < 10){
            $H = "0".$i;
        } else {
            $H = $i;
        };

        //Loop through the times that are booked and see if it is the same as the $H which is the current count of the loop so it should set skip to 1 if the time is booked.
        for ($x = 0; $x < $num_booked; $x++){
            if(date("H", strtotime($booked_times[$x-1]['Booking_Start'])) == $H){
                $skip = 1;
            }else{
                $skip = 0;
            };
        };

        if($skip != 1){
            if ($i < 10){
                echo '<option value="0'.$i.':00">0'.$i.':00 - 0'.$i.':55</option>';
                $i++;
            }else{
                echo '<option value='.$i.':00">'.$i.':00 - '.$i.':55</option>';
                $i++;
            };
        } else {
            $i++;
        };
    };
    echo "</select>";
};

But I think its pretty primitive but I am still working on it I think I am getting there I need to cut off all the times before the time actually now.

  • 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-06-01T06:38:32+00:00Added an answer on June 1, 2026 at 6:38 am

    I used somthing like this:

    <?php
    function mysql_fetch_rowsarr($result, $numass=MYSQL_BOTH) {
    $i=0;
    $keys=array_keys(mysql_fetch_array($result, $numass));
    mysql_data_seek($result, 0);
    while ($row = mysql_fetch_array($result, $numass)) {
      foreach ($keys as $speckey) {
        $got[$i][$speckey]=$row[$speckey];
      }
    $i++;
    }
     return $got;
    }
    
    function convertDate($date){
    $date_year=substr($date,1,4);
    $date_month=substr($date,6,7);
    $date_day=substr($date,8,10);
    $date=date("Y-m-d", mktime(0,0,0,$date_month,$date_day,$date_year));
    return $date; 
    };
    
    $is_ajax = $_REQUEST['is_ajax'];
    if (!isset($_POST['date'])) {
    echo "<option value='0' selected>Select Date...</option>";
    }else{
    include 'config.php';
    $conn = mysql_connect($host,$user,$pass);
    if (!$conn) {
        die('Could not connect: ' . mysql_error());
    };
    
    //Get rodays date
    date_default_timezone_set('Europe/London');
    $date = $_POST['date'];
    $check_date = convertDate($date);
    $today = date("Y-m-d");
    $the_hour = date("H");      
    
    mysql_select_db($db, $conn);
    mysql_set_charset('utf8',$conn);
    
    $booking_check = mysql_query("SELECT * FROM Booking WHERE Booking_Start LIKE '%$check_date%'");
    
    //if no bookings just echo the entire form but if there is do the else
    if (mysql_num_rows($booking_check) == 0) {
        //counter set to 23 because of 0
        $counter = 23;
        $i = 0;
    
        if($check_date == $today && $the_hour == 23){
            echo "<option value='0' selected>No Slots. Sorry.</option>";
        }else{
            while($i<=$counter) {
                if($check_date == $today){
                    if ($i > $the_hour){
                        if ($i < 10){
                            echo '<option value="0'.$i.':00">0'.$i.':00 - 0'.$i.':55</option>';
                            $i++;
                        }else{
                            echo '<option value="'.$i.':00">'.$i.':00 - '.$i.':55</option>';
                            $i++;
                        };
                    }else{
                        $i++;
                    };
                }else{
                    if ($i < 10){
                        echo '<option value="0'.$i.':00">0'.$i.':00 - 0'.$i.':55</option>';
                        $i++;
                    }else{
                        echo '<option value="'.$i.':00">'.$i.':00 - '.$i.':55</option>';
                        $i++;
                    };
                };
            };
        };
    } else {
        //counter set to 23 because of 0
        $counter = 23;
        $i = 0;
        $avalible_slots = 23;
        $booked_times = mysql_fetch_rowsarr($booking_check);
        $num_booked = mysql_num_rows($booking_check);
        $H = 0;
    
        if($check_date == $today && $the_hour == 23){
            echo "<option value='0' selected>No Slots. Sorry.</option>";
        }else{
            while($i<=$counter) {
                //$H is used to compare if the hour slot is booked this adds a 0 to the front of the varible if under 10 for the 24H time format.
                if ($i < 10){
                    $H = "0".$i;
                } else {
                    $H = $i;
                };
                //Loop through the times that are booked and see if it is the same as the $H which is the current count of the loop so it should set skip to 1 if the time is booked.
                $x = 0;
                while($x < $num_booked){
                    if(date("H", strtotime($booked_times[$x]['Booking_Start'])) == $H){
                        $skip = 1;
                        break;
                    }else{
                        $skip = 0;
                        $x++;
                    };
                };
                if($check_date == $today){
                    if($skip != 1 && $i > $the_hour){
                        if ($i < 10){
                            echo '<option value="0'.$i.':00">0'.$i.':00 - 0'.$i.':55</option>';
                            $i++;
                        }else{
                            echo '<option value="'.$i.':00">'.$i.':00 - '.$i.':55</option>';
                            $i++;
                        };
                    }else{
                        $i++;
                        $avalible_slots--;
                    };
                }else{
                    if($skip != 1){
                        if ($i < 10){
                            echo '<option value="0'.$i.':00">0'.$i.':00 - 0'.$i.':55</option>';
                            $i++;
                        }else{
                            echo '<option value="'.$i.':00">'.$i.':00 - '.$i.':55</option>';
                            $i++;
                        };
                    }else{
                        $i++;
                        $avalible_slots--;
                    };
                };
            };
            echo $avalible_slots;
            echo $num_booked;
        };
    };
    };
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using CakePHP 1.3 we have a booking system for hotel rooms. A check-availability form
I'm looking at making a booking system and I need to display all the
I am making a booking system where users can make appointments with each other.
Im making a simple booking system for our projectors at work. Here is the
I am making a registration form in PHP and when submitting the form Date(Check
An email confirmation gets sent when my website users making a booking. I have
I am making a booking app now and have a problem. I need a
I am making a booking comparison engine, and I have a very sensitive problem.
I am making a form that submits some values to a site for booking
Making UI programmatically is very powerful. But is there a way I would have

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.