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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:46:17+00:00 2026-06-12T04:46:17+00:00

I’m still leanring PHP/MySQL but have learned quite a bit thanks to codies on

  • 0

I’m still leanring PHP/MySQL but have learned quite a bit thanks to codies on StackOverflow. I’m trying to setup a sort of room reservations system using two tables:


SETUP:

Room price table: Has, prices for a type room a client may want to rent as well as the dates (day of week) they wish to use it. Pricing varies based on day of the week and per room.

I’ve setup a different table for each room type as each room type carries different pricing for each day of the week. So, There is an Alpha room table, Bravo room, etc. Within Alpha table are headers for the days of the week with pricing pre-entered into the rows.

Client info table: Has the name, address, date of room use, etc data for the specific client.

EXAMPLE:

Alpha-room price table:
Sun = $100; Mon = $200; Tue=$300 and so on.

Bravo-room price table:
Sun = $100; Mon = $200; Tue=$300 and so on.

Client data table:
ClientName; date-of-room-use; address; day_subtotal; grand_total.

QUESTION:

I’m trying to find PHP code that will:

  1. look at the date of room use in the client data table,
  2. look up the associated cost for that date in the specific room pricing table,
  3. record that unit cost in the day subtotal of the client data table
  4. and sum a grand total in the grand total row of the client data
    table (assuming the room may be used more than one day by the
    customer).

I know there’s something to do with join but I’m finding it difficult to grasp the concept and, if someone can demonstrate using this example, I think I will have a better understanding of how to work this sort of transaction.

Thank you ALL in advance for your suggestions or alternatvie approaches.

  • 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-12T04:46:19+00:00Added an answer on June 12, 2026 at 4:46 am

    First, you should separate your database slightly, you should have four tables. rooms, prices, clients and bookings. Setup somewhat like this…

    rooms should have the following fields: id, name and description.

    prices should have the following fields: id, price, room_id and day.

    clients should have the following fields: id and whatever else you want to store on the user, such as first and last names, phone number or whatever.

    bookings should have the following fields: id, client_id, room_id, started_at and ended_at. Preferably the started_at and ended_at fields will be an int, filled with PHP’s time() method.

    You can add any extra fields you want/need to the tables.

    With the tables separated out like this, you will be able to properly query the database. So to answer your questions…

    1. look at the date of room in use…
      You can now query to see if a room is in use on a specific date by doing the following…

      <?php
      $selectedDate= mktime(); // Create a UNIX timestamp based on the day the user selected.
      $query = "SELECT r.name, r.description
                FROM rooms r, bookings b
                WHERE b.room_id = r.id
                AND b.started_at < $selectedDate
                OR b.ended_at > $selectedDate";
      $result = $pdo->query($query);
      ?>
      
    2. Look up cost for that date

      <?php
      $selectedDate = mktime() // Create a UNIX timestamp based on the day the user selected
      $dayOfWeek = Date('N', $selectedDate); // This will give the numerical day of the week.
      $query = "SELECT price
                FROM prices
                WHERE room_id = $roomId
                AND day = $dayOfWeek";
      $result = $pdo->query($query);
      ?>
      
    3. Record that unit cost in the client table

      Doing this is just silly on account of already having the information in another table. Never recreate the same information in a database. If you are, you have built your database incorrectly.

    4. Grand total in the customer table

      Again, silly… don’t recreate data…

      1. Though, to find that information out, you would first need to do a query on the bookings table, and see the start and end date for which the user will be occupying the room.

      2. Do a calculation on how long the client will be in the room for, (ended_at – started_at) / 86400, (86400 is the number of seconds in a day) that will give the number of days the client is in the room for.

      3. Now that you know which days, and how long the client will be in the room, you can dynamically create a sql call to select the days of the week you need, remember Date('N', $timeStamp) will give you the numerical day of the week for a given timestamp.

      4. Then it is just a matter of doing simple addition.

    I have given you the basics here, You can modify the query from answer one to show you if a room is available to be booked within the time frame the user asked for.

    I hope that covers everything you asked about…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.