Hallo I'm trying to do a select query that should disable all the dates in my calendar based on the ones that are in the db. but for some reason it only want to do the last one entered in the db and I also can't disable the in between dates ( so for example between 4-7-2022 and 7-7-2022). I have been trying do use a for loop/ for each loop en eventually a while loop. but I'm not seeing where the problem is?
<?php include "config.php"; ?>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Display multiple months</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<?php
//https://www.syncfusion.com/forums/152695/i-want-to-disable-the-datepicker-holiday-dates-which-are-stored-in-database
//https://www.google.com/search?q=javascript+make+connection+to+db&rlz=1C1CHZN_nlNL992NL992&oq=javascript+make+connection+to+db&aqs=chrome..69i57j33i160l3j33i22i29i30l2.7107j0j15&sourceid=chrome&ie=UTF-8
$huis_ID = "1";
$sql = "SELECT start_datum, eind_datum FROM reserveringen WHERE huis_ID = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $huis_ID);
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
// do something
// foreach($data as $row):
$start_datum = date('d-m-Y', strtotime($row['start_datum']));
$eind_datum = date('d-m-Y', strtotime($row['eind_datum']));
//echo $eind_datum , "<br>";
}
// $data = $result->fetch_all(MYSQLI_ASSOC);
// if ($data):
?>
<script>
$(document).ready(function() {
//make an array of disable dates
//needs to be dates from db
var dates = ["<?php echo $start_datum; ?>", "<?php echo $eind_datum; ?>"];
//var dates = ["10-07-2022", "15-07-2022", "30-07-2022", "11-07-2022", "16-07-2022", "31-07-2022"];
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
return [dates.indexOf(string) <= -1];
}
console.log(dates);
$( "#datepicker" ).datepicker({
dateFormat : "dd/mm/yy",
todayHighlight:'TRUE',
numberOfMonths: 1,
minDate:0,
showButtonPanel: true,
beforeShowDay: disableDates
});
});
$(document).ready(function() {
//needs to be dates from db
var dates = ["<?php echo $start_datum; ?>", "<?php echo $eind_datum; ?>",];
for(var i = 0; i < dates. length ; i++){
console. log(dates[i])
}
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
return [dates.indexOf(string) == -1];
}
//dit is voor als de rest werkt maar het zou de tussendagen weg moeten halen
// if (dates <= <php $eind_datum ?> && dates => <php $start_datum ?>){
// console.log(testing);
// }
//var dates = ["10-07-2022", "15-07-2022", "30-07-2022","11-07-2022", "16-07-2022", "31-07-2022"];
$( "#datepicker1" ).datepicker({
dateFormat : "dd/mm/yy",
numberOfMonths: 1,
minDate:1,
showButtonPanel: true,
beforeShowDay: disableDates,
});
});
</script>
<!--
No data found
-->
</head>
<body>
<div class="check in mb-3">
<label for="start_date" class="form-label">Start datum: </label>
<input type="text" class="form-control" id="datepicker" name="datepicker"/>
</div>
<div class="check in mb-3">
<label for="start_date" class="form-label">Eind datum: </label>
<input type="text" class="form-control" id="datepicker1" name="datepicker1"/>
</div>
</body>
</html>