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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:10:13+00:00 2026-06-12T20:10:13+00:00

I am making code for a studio reservation where customers can reserve for how

  • 0

I am making code for a studio reservation where customers can reserve for how many hours in a day… for example, a customer inputs
Date: October 17, 2011
Time In: 10:30:00 am
Time out: 11:30:00 am

In that case, another customer must not be able to input a time in/ timeout between 10:30 to 11:30 am with the same date.

before making a database, i have tried this code:

<?php 
$resttimefrom='10:00:00 am';
$resttimeto='11:00:00 am';
$reserve='11:01:00 pm';
$datedat='2012-10-14';


$st_time    =   strtotime($resttimefrom);
$end_time   =   strtotime($resttimeto);
$reserve   =   strtotime($reserve);
$datedat   =   strtotime($datedat);

print $st_time; echo "<br>";
print $end_time; echo "<br>";
print $reserve; echo "<br>";

if ($reserve => $st_time and $reserve =< $end_time)
{
echo "sorry, not available";
}
else
{
echo "ok!";
}

?>

it can already restrict the time, but not yet the day.

it’s just a sample so that I will know what to do if i’ll transfer it into database.

my problem is this:

I have a table named reserve with 3 columns… timein, timeout, dateres
three records have been inputted,

October 15, 2011, 10:30-11:30
October 15, 2011, 1:00-2:30
October 15, 2011, 5:30-8:30

how can I retrieve these records to use it on my code above? instead of these:

$resttimefrom='10:00:00 am';
    $resttimeto='11:00:00 am';
    $reserve='11:01:00 pm';
    $datedat='2012-10-14';

how can I change 10:00:00 am to all records in my database?

I have very limited knowledge about php and mysql… 🙁 please someone help me. please please please

  • 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-12T20:10:14+00:00Added an answer on June 12, 2026 at 8:10 pm

    I would suggest you reconsider the way you deal with the duration of reservations. Rather than having a date_reserved simply have time_in, and time_out as datetimes. I would also use the 24hour format instead of 12hr (with AM & PM). So you would have:

    $timeInStr  = '2012-10-14 10:00:00';
    $timeOutStr = '2012-10-14 11:00:00';
    

    Just for completeness, here is some code to insert data into the table:

    $pdo = new PDO(
            "mysql:dbname=stack_overflow;host=127.0.0.1",
            $username,
            $password);
    
    // prepare the insert statement
    $statement = $pdo->prepare("
            INSERT INTO `reserve`(`time_in`, `time_out`)
            VALUES (:time_in, :time_out)");
    
    // bind param values
    $statement->bindParam(':time_in', $timeInStr, PDO::PARAM_STR);
    $statement->bindParam(':time_out', $timeOutStr, PDO::PARAM_STR);
    
    $statement->execute();
    

    In order to determine whether a reservation request would conflict with a previously set reservation, query the database whether the reservation request (equivalent to your $reserve variable) is between the time_in & time_out of any reservation.

    In this case, I would count how many previous reservations would overlap with the requested reservation time.

    $statement = $pdo->prepare("
        SELECT COUNT(`id`)
        FROM `reserve`
        WHERE :reserve_request_time BETWEEN `time_in`
        AND `time_out`");
    
    $statement->bindParam(
            ':reserve_request_time',
            '2012-10-14 10:30:00',
            PDO::PARAM_STR);
    
    $statement->execute();
    $result = $statement->fetch();
    
    // if an overlapping reservation was found "sorry, not available"
    if (0 < (int) $result['COUNT(`id`)']) {
        echo "sorry, not available";
    }
    else {
        echo "ok!";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find the problem. Why is this code making many copies of the
The following is some code for making sure people can't submit if the value
I've got Code Contracts working fine from inside Visual Studio 2010, but I can't
As far as I can tell, Visual Studio 2008 provides two ways of making
I would like to start making code patches to Rails. Are there any good
I'm working on making some code using metaheuristics for finding good solutions to the
I'm not talking about making portable code. This is more a question of distribution.
I'm looking for strategies and articles on making Carbon code 64-bit ready. Carbon for
I am wondering if there is any technique out there for making HTML code
The following code is making my app crash at line 3 without an error

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.