Jump to content

cant see sunday in calander


baraktw

Recommended Posts

hello this script show in calander days and hours you can pick for appointment but i dont see sunday in the calander the config of the day is taking from DB can someone help me i think there is something here but cant fix that thank you alot

$appointment_date = date('Y-m-d');
 for($i = 0; $i <10; $i++)
                {
                    $appointment_date = date('Y-m-d', strtotime($appointment_date . ' +1 day'));
                    echo "<div class = 'appointment_day'>";
                        echo date('D', strtotime($appointment_date));
                        echo "<br>";
                        echo date('d', strtotime($appointment_date));
                    echo "</div>";
                }
  <!-- NEXT 10 DAYS -->

        <div class="appointments_days">
            <?php
                
                $appointment_date = date('Y-m-d');

                for($i = 0; $i <10; $i++)
                {
                    $appointment_date = date('Y-m-d', strtotime($appointment_date . ' +1 day'));
                    echo "<div class = 'appointment_day'>";
                        echo date('D', strtotime($appointment_date));
                        echo "<br>";
                        echo date('d', strtotime($appointment_date));
                    echo "</div>";
                } 
            ?>
        </div>

        <!-- DAY HOURS -->

        <div class = 'available_booking_hours'>
            <?php

                //SELECTED SERVICES
                $desired_services = $_POST['selected_services'];
                
                //SELECTED EMPLOYEE
                $selected_employee = $_POST['selected_employee'];

                //Services Duration - End time expected
                $sum_duration = 0;
                
                foreach($desired_services as $service)
                {
                    
                    $stmtServices = $con->prepare("select service_duration from services where service_id = ?");
                    $stmtServices->execute(array($service));
                    $rowS =  $stmtServices->fetch();
                    $sum_duration += $rowS['service_duration'];
                    
                }
        
        
                $sum_duration = date('H:i',mktime(0,$sum_duration));
                $secs = strtotime($sum_duration)-strtotime("00:00:00");


                $open_time = date('H:i',mktime(9,0,0));

                $close_time = date('H:i',mktime(22,0,0));

                $start = $open_time;

                $secs = strtotime($sum_duration)-strtotime("00:00:00");
                $result = date("H:i:s",strtotime($start)+$secs);


                $appointment_date = date('Y-m-d');

                for($i = 0; $i < 10; $i++)
                {
                    echo "<div class='available_booking_hours_colum'>";

                        $appointment_date = date('Y-m-d', strtotime($appointment_date . ' +1 day'));
                        $start = $open_time;
                        $secs = strtotime($sum_duration)-strtotime("00:00:00");
                        $result = date("H:i:s",strtotime($start)+$secs);

                        $day_id = date('w',strtotime($appointment_date));
                        
                        while($start >= $open_time && $result <= $close_time)
                        {
                            // Check If the employee is available

                            $stmt_emp = $con->prepare("
                                Select employee_id
                                from employees_schedule
                                where employee_id = ?
                                and day_id = ?
                                and ? between from_hour and to_hour
                                and ? between from_hour and to_hour
                                   
                            ");
                            $stmt_emp->execute(array($selected_employee,$day_id,$start, $result));
                            $emp = $stmt_emp->fetchAll();

                            //If employee is available

                            if($stmt_emp->rowCount() != 0)
                            {

                                //Check If there are no intersecting appointments with the current one
                                $stmt = $con->prepare("
                                    Select * 
                                    from appointments a
                                    where
                                        date(start_time) = ?
                                        and
                                        a.employee_id = ?
                                        and
                                        canceled = 0
                                        and
                                        (   
                                            time(start_time) between ? and ?
                                            or
                                            time(end_time_expected) between ? and ?
                                        )
                                ");
                                
                                $stmt->execute(array($appointment_date,$selected_employee,$start,$result,$start,$result));
                                $rows = $stmt->fetchAll();
                    
                                if($stmt->rowCount() != 0)
                                {
                                    //Show blank cell
                                }
                                else
                                {
                                    ?>
                                        <input type="radio" id="<?php echo $appointment_date." ".$start; ?>" name="desired_date_time" value="<?php echo $appointment_date." ".$start." ".$result; ?>">
                                        <label class="available_booking_hour" for="<?php echo $appointment_date." ".$start; ?>"><?php echo $start; ?></label>
                                    <?php
                                }
                            }
                            else
                            {
                                //Show Blank cell
                            }
                            

                            $start = strtotime("+15 minutes", strtotime($start));
                            $start =  date('H:i', $start);

                            $secs = strtotime($sum_duration)-strtotime("00:00:00");
                            $result = date("H:i",strtotime($start)+$secs);
                        }

                    echo "</div>";
                }
            ?>
        </div>
    </div>
<?php
}
else
{
    header('location: index.php');
    exit();
}

 

Link to comment
Share on other sites

22 hours ago, Barand said:

PS As an aside, you have a query to find employees schedules overlapping with the time period A - B.

The possible overlapping cases are shown below

image.png.84cd29ecb86f86d35508330bdaf85dc3.png

The following WHERE clause will find all 4 types whereas yours won't.

WHERE S < B AND E > A

its send this error and now nothing in calander

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\calendar.php:214 Stack trace: #0 C:\xampp\htdocs\calendar.php(214): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\calendar.php on line 214

 

 

Link to comment
Share on other sites

Of course, to risk stating the obvious, you will have to substitute your parameters and column names.

$stmt_emp = $con->prepare("
                                Select employee_id
                                from employees_schedule
                                where employee_id = ?
                                and day_id = ?
                                and to_hour > ?
                                and from_hour < ?
                                   
                            ");
$stmt_emp->execute(array($selected_employee,$day_id,$start, $result));

 

Link to comment
Share on other sites

16 hours ago, Barand said:

Of course, to risk stating the obvious, you will have to substitute your parameters and column names.

$stmt_emp = $con->prepare("
                                Select employee_id
                                from employees_schedule
                                where employee_id = ?
                                and day_id = ?
                                and to_hour > ?
                                and from_hour < ?
                                   
                            ");
$stmt_emp->execute(array($selected_employee,$day_id,$start, $result));

 

still get that error tell me where i am wrong and if you can fix the code. i really grateful for your help until now.

                                $stmt = $con->prepare("
                                Select * 
                                from appointments a
                                where
                                    date(start_time) = ?
                                    and
                                    a.employee_id = ?
                                    and
                                    canceled = 0
                                    and
                                    ((start_time >= ? and start_time <= ?)
                                    or
                                    (end_time >= ? and end_time_expected <= ?))
                                    and (start_time < end_time_expected)
                                    and ((start_time < ? and end_time_expected > ?) OR (start_time > ? and end_time_expected < ?))
                            ");
$stmt->execute(array($appointment_date,$selected_employee,$start,$result,$start,$result));

 

 

 

 $stmt_emp = $con->prepare("
                                Select employee_id
                                from employees_schedule
                                where employee_id = ?
                                and day_id = ?
                                and to_hour > ?
                                and from_hour < ?
                                   
                            ");
$stmt_emp->execute(array($selected_employee,$day_id,$start, $result));

 

Link to comment
Share on other sites

i have fixed that error but still not seeing hours in sunday.

 

                                $stmt = $con->prepare("
                                Select * 
                                from appointments a
                                where
                                    date(start_time) = ?
                                    and
                                    a.employee_id = ?
                                    and
                                    canceled = 0
                                    and
                                    ((start_time >= ? and start_time <= ?)
                                    or
                                    (end_time_expected >= ? and end_time_expected <= ?))
                                    and (start_time < end_time_expected)
                                    and ((start_time < ? and end_time_expected > ?) OR (start_time > ? and end_time_expected < ?))
                                ");
                                
                                $stmt->execute(array($appointment_date, $selected_employee, $start, $result, $start, $result, $start, $result, $start, $result));
                            $stmt_emp = $con->prepare("
                                Select employee_id
                                from employees_schedule
                                where employee_id = ?
                                and day_id = ?
                                and to_hour > ?
                                and from_hour < ?
                                   
                            ");
$stmt_emp->execute(array($selected_employee,$day_id,$start, $result));

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.