2016-12-04 24 views
1

我有一個住宅預訂系統,我可以禁用特定的日子,但從註冊的日子我的表中禁用日子。 我有2個表habitacionesreservas使用數據庫(mysql,php)在住宅系統中的Disponibility(禁用天數)

table habitaciones (room) 
id_habitacion integer.. 

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

我從llegada輸入和salida

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

在腳本日期選擇器,我有:

<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> 

這工作: Disable days ["12-12-2016", "13-12-2016", "14-12-2016", "14-12-2016"]

現在我已經從表reservas select * from reservas

的日期,我最後需要營救表reservas和殘疾人天 這個日期llegadasalida(其中id_habitacion ....)(我的英語是多還是少)

之間
+0

問題是什麼? – Blag

+0

我需要從我的數據庫禁用這些日子,而不是從此代碼:var disableddates = [「12-12-2016」,「13-12-2016」,「14-12-2016」,「14-12-2016」] ; 我不知道如何從表reservas日期,這個日期把禁用 –

+0

你有沒有嘗試過一些PHP/SQL來做到這一點?如果是的話,請把它放在你的問題上;) – Blag

回答

1

這可能會幫助你做你想要什麼:

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).']';