2日期之间的汽车可用性,逗号分隔数据

时间:2016-10-03 10:12:28

标签: php mysql

我无法按日期列出可用的汽车。这是ma数据和代码。

booking_tbl

enter image description here

car_tbl

enter image description here

我有一个按日期过滤可用性的代码:          从          至     

<input type="submit" name="button" id="button" value="Filter" />
  </label>
  <a href="q_search1_form.php">reset</a>
</form>
<script>
    $(function() {
        var dates = $( "#from, #to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            dateFormat: 'yy-mm-dd',
            onSelect: function( selectedDate ) {
                var option = this.id == "from" ? "minDate" : "maxDate",
                    instance = $( this ).data( "datepicker" ),
                    date = $.datepicker.parseDate(
                        instance.settings`enter code here`.dateFormat ||
                        $.datepicker._defaults.dateFormat,
                        selectedDate, instance.settings );
                dates.not( this ).datepicker( "option", option, date );
            }
        });
    });
    </script>

这是我的查询代码:

<?php
include("config.php");
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) { die('Failed to connect to server: ' . mysql_error()); }
$db = mysql_select_db(DB_DATABASE);
if(!$db) { die("Unable to select database"); }
$start =$_POST['from'];
$end =$_POST['to'];

$query="SELECT car.id, car.description, car.name, car.status, booking.book_id FROM car LEFT JOIN booking ON booking.id_car=car.id ";
$query.="WHERE (start_date BETWEEN CAST('$start' AS DATE) AND CAST('$end' AS DATE) OR start_date IS NULL) ";
$query.="AND (end_date BETWEEN CAST('$start' AS DATE) AND CAST('$end' AS DATE) OR end_date IS NULL) ";
$query.="AND status = 'available'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){

?>
<input type="checkbox" name="car[]" id="car" value="<?php echo $row['id'];?> "> <?php echo $row['name'];?><br>

<?php
}mysql_close();?>

我使用以下代码插入数据:

$id_car = @implode(',', $_POST['car']);

我的问题是我想检查哪些车或车可用(例如查询中的2016-10-02也显示为vw,但此车已预订)。 如果我为2016-10-03插入新的预订:梅赛德斯,在我的新查询中插入后,它也显示梅赛德斯,我不知道为什么,因为它已经预订。

0 个答案:

没有答案