简体   繁体   English

如何在预订系统上只选择可用房间?

[英]How to select just the available rooms on a reservation system?

I'm trying to build a reservation system for a hotel and I don't know how to select just the available rooms?我正在尝试为一家酒店建立一个预订系统,但我不知道如何只选择可用房间? I have two tables: table of rooms with called "chambre" it have: id, libelle and table called" reservation_client" it has: id, id_client, id_chambre, start, end .我有两个表:名为“chambre”的房间表,它有: id, libelle和名为“reservation_client”的表,它有: id, id_client, id_chambre, start, end For the start and end they are the start date of reservation and the end of reservation对于开始和结束,它们是预订​​的开始日期和预订的结束日期

This is my select form:这是我的选择表格:

<div class="form-group">
    <label class="col-sm-2 control-label">Chambre</label>
    <div class="col-sm-9">
        <select class="form-control" name="id_chambre">
            <option>Selectionnez une chambre</option>

            <?php 
                 /*echo $req2=$bdd->query('SELECT * FROM reservation_client WHERE $donnees["start"]!==$_POST["start"] ' )/*or die (print_r($bdd->errorinfo()))*/
                $req=$bdd->query('SELECT * FROM chambre' )/*or die (print_r($bdd->errorinfo()))*/;

                $req2=$bdd->query('SELECT * FROM reservation_client ' );
                    while ($donnees = $req->fetch() ) { 

                  echo"<option  value='".$donnees['id']."'>".($donnees['libelle']) ."</option> "  ;                                                 
                      }                   
              ?>

        </select>
    </div>
</div>

I tried this code but without any result:我试过这段代码,但没有任何结果:

$req2=$bdd->query('SELECT * FROM reservation_client WHERE start<end AND end>star ' );

You just need to join the table, if you don't know how to do that then do some research into mysql LEFT JOIN and INNER JOIN.你只需要加入表,如果你不知道怎么做,那么对 mysql LEFT JOIN 和 INNER JOIN 做一些研究。 In this case you want to LEFT JOIN so that you can include rows without a matching reservation.在这种情况下,您希望 LEFT JOIN 以便您可以包含没有匹配保留的行。 I can't write it exactly becaus I don't know your tables but this example should give you an idea:我不能完全写它,因为我不知道你的表,但这个例子应该给你一个想法:

SELECT * FROM chambres c
LEFT JOIN reservation_client rc ON rc.chambre = c.id
WHERE rc.date BETWEEN (your date range)
AND rc.id IS NOT NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM