我正在嘗試比較租金開始和租金結(jié)束的兩個日期,但數(shù)據(jù)庫中的某些車輛可能已經(jīng)在這些日期租用我已經(jīng)有一個代碼阻止用戶在兩個日期之間預(yù)訂汽車,但在那之后它仍然被阻止if( empty($content) ){ extract($_POST); // here i extract my _post if( !empty($idmembre) ){ $vehicule = execReq( "SELECT * FROM vehicule WHERE idvehicule=:idvehicule", array( 'idvehicule' => $idvehicule )); $infoVehicule = $vehicule->fetch(); $agence = $infoVehicule['agences_idagences']; $timestamp1 = strtotime($date_heure_depart); $timestamp2 = strtotime($date_heure_fin); // here i create two timestamps to compare with what i have en my database $date_deja_prise = execReq( "SELECT * FROM commande WHERE vehicule_idvehicule=:idvehicule", array( 'idvehicule' => $idvehicule )); while( $date = $date_deja_prise->fetch() ){ if( !empty($date) ){ // here if one vehicle has a date of rent it checks evry one to check if the date is taken $date_debut = strtotime($date['date_heure_depart']); $date_fin = strtotime($date['date_heure_fin']); if( ($date_debut <= $timestamp1 || $timestamp2 <= $date_fin) ){ $content .= '<div class="alert alert-danger">Le véhicule '.$infoVehicule['titre'].' est déjà louer du '.$date['date_heure_depart'].' au '.$date['date_heure_fin'].' inclu</div>'; } } }所以基本上它可以在我的 phpmyadmin 頁面中創(chuàng)建一行,在那里預(yù)訂汽車一段時間,之后如果我嘗試預(yù)訂另一輛車,但所有日期都不同,我不能
1 回答

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個贊
我認(rèn)為你的問題是這條線if( ($date_debut <= $timestamp1 || $timestamp2 <= $date_fin) ){
。您只檢查新開始時間是否 <= 比現(xiàn)有開始時間,以及新結(jié)束時間是否 >= 比現(xiàn)有開始時間。您需要檢查開始日期或結(jié)束日期是否在現(xiàn)有日期之間。
if( ($date_debut <= $timestamp2 && $timestamp1 <= $date_fin) ){
- 1 回答
- 0 關(guān)注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消