I have been trying to explain myself to google but with my limited english it isn't really getting me far.
I have this calendar that has disabled dates in them based on the dates that are in the db.
these dates have been put in an array.
let's say the array has the dates = 4/7/2022 and 7/7/2022
4/7/2022 is start_date
7/7/2022 is end_date
Right now it only disables those two dates. but what I want is some kind of loop that loops adds 1 disabled day from start_date until it reaches end_date
FULL CODE
<pre><?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
$huis_ID = $_GET['ID'];
$arraysession=array();
$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)){
$start_datum = date('d-m-Y', strtotime($row['start_datum']));
$eind_datum = date('d-m-Y', strtotime($row['eind_datum']));
array_push($arraysession, $start_datum, $eind_datum);
}
$array_to_json=json_encode((array)$arraysession);
?>
<script>
$(document).ready(function() {
var dates = <?php echo $array_to_json?>;
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
return [dates.indexOf(string) <= -1];
}
$( "#datepicker" ).datepicker({
dateFormat : "dd/mm/yy",
todayHighlight:'TRUE',
numberOfMonths: 1,
minDate:0,
showButtonPanel: true,
beforeShowDay: disableDates
});
});
$(document).ready(function() {
var dates = <?php echo $array_to_json ?>;
console.log(dates);
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
for(var i = dates; i < $array_to_json. length ; i++){
console. log(i);
}
return [dates.indexOf(string) == -1];
}
$( "#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>
What I have tried:
var dates = <?php echo $array_to_json?>;
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
for(var i = dates; i < dates. length ; i++){
console. log(string[i]);
}
return [dates.indexOf(string) == -1];
}
but this doesn't change anything and just shows the start_date and the end_date
then I tried
var dates = <?php echo $array_to_json?>;
function disableDates(date) {
var string = $.datepicker.formatDate('dd-mm-yy', date);
for(var i = string; i < string. length ; i++){
console. log(string[i]);
}
return [dates.indexOf(string) == -1];
}
and this shows the same thing.
tried switch up the positions of array and sting but that doesn't work either. what error am i making