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

The Archive Base Latest Questions

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

I’m working on an online booking system and currently use a table bookings (id,

  • 0

I’m working on an online booking system and currently use a table bookings (id, slot id, treatment, user, date), treatments (id, name, description, duration), timeslots(id, time).
In the first page of booking you see treatment options, and a calender datepicker. Once you pick the calender date it sends this off to a php page and returns a list of available timeslot.

In this php page I have an array of booked times, an array of all the slots. The booked times are substracted from all available slots and the remaining array(all available slots) is then shown to the user so they see all times they can book an appointment.

Now I want to add a duration variable into the mix. This means that array of booked timeslots (say 3,5) and available timeslots(1,2,3,4,5,6,7,8,9,10) if the duration is bigger than two, the result of taking the first array off the second is (6,7,8,9,10). if the duration is 2, (1,2,6,7,8,9,10) and if it is 1 (1,2,4,6,7,8,9,10). Does anyone know how I can do such a thing?

Just for help with suggestions this is the php page:

<?php
include('connection.php');
error_reporting(E_ALL);
 $treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];

if(!isset($treatment) && isset($bookdate)){

$else = mysql_query("SELECT * FROM SLOTS");
echo '<SELECT>';
while($array_else = mysql_fetch_array($else)){
echo "<OPTION value=".$array_else['SL_ID'].">".$array_else['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}else{

    $exp = explode("-", $bookdate);
    //determine what day of the week it is
    $timestamp = mktime(0,0,0,$exp[1],$exp[0],$exp[2]);
    $dw = date( "w", $timestamp); // sun0,mon1,tue2,wed3,thur4,fri5,sat6

    //find bookings with same date
    $q1 = mysql_query("SELECT BOOK_SLOT_ID FROM BOOKINGS WHERE BOOK_DATE='$bookdate'");
    //make array of booking slots
    $array1 = array();
    while ($s1 = mysql_fetch_array($q1)) {
    $array1[] = $s1['BOOK_SLOT_ID'];
    }
    $q2 = mysql_query("SELECT SL_ID FROM SLOTS");
    //make array of all slots
    $array2 = array();
    while ($s2 = mysql_fetch_array($q2)) {
    $array2[] =  $s2['SL_ID'];
    }
        if($dw == 6){
        $q = mysql_query("SELECT SL_ID FROM SLOTS ORDER BY SL_ID DESC LIMIT 4");
        $array = array();
        while ($s = mysql_fetch_array($q)) {
        $array[] = $s['SL_ID'];}
        $array_res_merge = array_merge((array)$array1,(array)$array);
        $arr_res = array_diff($array2, $array_res_merge);
        }elseif($dw != 6){
        //remove bookings from all slots
        $arr_res = array_diff($array2, $array1);
        }
    echo '<div>';
    //make selectable options of results
    echo '<SELECT id="timeslots">';
    foreach($arr_res as $op){
    $r = mysql_query("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'");
    $q3 = mysql_fetch_array($r);
    echo "<OPTION value=".$op.">".$q3['SL_TIME']."</OPTION>";
    }
    echo '</SELECT>';
    echo'</div>';
}

?>

Any help with this issue is greatly appreciated.

  • 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-12T17:17:52+00:00Added an answer on June 12, 2026 at 5:17 pm

    I would like to point out that improving the description of your variables by giving better names would help read the code. I will point out the logic since it would take a while to figure out your variables…

    $my_slots_id = array(1,2,3,4,5,6,7,8,9);
    $my_bookings = array(array("id"=>2,"duration"=>2),array("id"=>5,"duration"=>1));
    foreach($my_bookings as $booking){
        array_splice($my_slots_id,array_search($booking["id"],$my_slots_id),$booking["duration"]);
    }
    

    Use array_slice to do the remove from the array. First param is the array, second param is the start key, and third param is the interesting one: it defines how many to take off.

    To remove the items starting at the id and going backward, simply do this:

    array_splice($my_slots_id,array_search($booking["id"],$my_slots_id)-$booking["duration"],$booking["duration"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.