baraktw Posted January 15, 2023 Share Posted January 15, 2023 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/ Share on other sites More sharing options...
Barand Posted January 15, 2023 Share Posted January 15, 2023 Below is the result of my running your for() loop. The highlighted bit look very much like Sunday to me Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604702 Share on other sites More sharing options...
Barand Posted January 15, 2023 Share Posted January 15, 2023 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 The following WHERE clause will find all 4 types whereas yours won't. WHERE S < B AND E > A Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604703 Share on other sites More sharing options...
baraktw Posted January 16, 2023 Author Share Posted January 16, 2023 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604728 Share on other sites More sharing options...
Barand Posted January 16, 2023 Share Posted January 16, 2023 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)); Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604729 Share on other sites More sharing options...
baraktw Posted January 17, 2023 Author Share Posted January 17, 2023 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)); Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604759 Share on other sites More sharing options...
baraktw Posted January 17, 2023 Author Share Posted January 17, 2023 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)); Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604760 Share on other sites More sharing options...
Barand Posted January 17, 2023 Share Posted January 17, 2023 You have a prepared statement with 10 placeholders but your execute() only provides 6 values Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604761 Share on other sites More sharing options...
Barand Posted January 17, 2023 Share Posted January 17, 2023 1 hour ago, baraktw said: but still not seeing hours in sunday. As output is dependent on employee schedule and overlapping appointments, and I have no idea what is in your data, then you are on your own. Quote Link to comment https://forums.phpfreaks.com/topic/315805-cant-see-sunday-in-calander/#findComment-1604766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.