1

I have a booking system from a residential and I can disable days specific but not days from my table with the days registered. I have 2 tables habitaciones and reservas

table habitaciones  (room)
id_habitacion integer..

 table `reservas` (bookings)
`id_reserva integer`
 id_habitacion   integer
`llegada date`     (startdate)
`salida date`       (enddate)

I have input from llegada and salida

<input style="height: 31px;" id="datepicker2" class="form-control" name="llegada">
<input style="height: 31px;" id="datepicker3" class="form-control" name="salida">

In the script datepicker I have:

<script>
var disableddates = ["12-12-2016", "13-12-2016", "14-12-2016", "14-12-2016"];

function DisableSpecificDates(date) {
    var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
    return [disableddates.indexOf(string) == -1];
  }
$(function() {
  $("#datepicker2").datepicker({
    beforeShowDay: DisableSpecificDates
  });
}); 
</script>

This its work: Disable days ["12-12-2016", "13-12-2016", "14-12-2016", "14-12-2016"]

Now I have dates from table reservas select * from reservas

And I Finally need rescue this dates from table reservas and disabled days between llegada and salida (where id_habitacion ....)(my english is more or less)

  • What is the problem ? – Blag Dec 05 '16 at 01:11
  • I need the days disables from my database not from this code :var disableddates = ["12-12-2016", "13-12-2016", "14-12-2016", "14-12-2016"]; I do not know how take dates from table reservas, and this dates put disables – Diana Letelier Dec 05 '16 at 02:20
  • have you tried some PHP / SQL to do that ? if yes, put it on your question please ;) – Blag Dec 05 '16 at 07:18

1 Answers1

1

This'll probably help you to do what you want :

PHP: Return all dates between two dates in an array

// add a $pdo link here

$req = $pdo->prepare('SELECT llegada, salida 
    FROM reservas 
    WHERE id_habitacion = :id');

$req->execute(array('id'=>$id));

$data = $req->fetch();

$period = new DatePeriod(
     new DateTime($data['llegada']),
     new DateInterval('P1D'),
     new DateTime($data['salida'])
);

$arrDates = iterator_to_array($period);
$arrDates[] = $data['salida']; // add the last date
$dates = '['.implode(',', $aDates).']';
Community
  • 1
  • 1
Blag
  • 5,818
  • 2
  • 22
  • 45