从日期选择器逐日搜索 [英] Daywise search from the datepicker

查看:48
本文介绍了从日期选择器逐日搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表单.php

<div class="left"><b>离开</b><br/><input type="text" name="source_point" id="source_point"/></div><div class="right"><b>前往</b><br/><input type="text" name="destination" id="destination"/></div><div class="dt">旅程日期

<script type="text/javascript">$(函数(){$( "#datepick" ).datepicker({ minDate: 0});});<div><input type="submit" value="提交"/>

</表单>

这是我的表格,当我通过它搜索公交车时,无论我给出什么日期,它都会显示我数据库中的公交车(按源点和目的地点搜索),但我已经插入了公交车的可用天数.我想根据各自的日期搜索公共汽车.这意味着当我在我的日期选择器中输入一个日期时,它应该从数据库中搜索它的相应日期并显示结果,如果在那一天巴士不可用,它不应该显示任何结果.

搜索.php

<td><input name="bus_name" type="text" value="<?php echo $row['bus_name'];?>"class="input_box"/>

解决方案

我们确实需要查看您的服务器端代码和数据结构来确定这一点.

理想情况下,您希望捕获日期范围,然后调整您的 SQL 语句以仅返回基于该范围的值.

$datepick 将是您表单中的值,可能是经过清理的 $_POST['datepicke'];

这将使当天的上午 12:00 到下一个日期的上午 12:00,因此在一天内

<块引用>

示例 SQL:SELECT * FROM bus WHERE 出发 => $datepick AND出发 <= DATE_ADD($datepick, INTERVAL 1 DAY)"

希望有帮助

form.php

<form action="search_bus.php" id="search_form1" style="padding:10px;">
    <div class="left"><b>Leaving From</b><br /><input type="text" name="source_point" id="source_point"/></div>
    <div class="right"><b>Going To</b><br /><input type="text" name="destination" id="destination"/></div>
    <div class="dt"> 
        Date of Journey <input id="datepick" size="19" name="datepick" class="text_box2" title="Departure Date" />
    </div>

    <script type="text/javascript">
        $(function() {
            $( "#datepick" ).datepicker({ minDate: 0});
        });
    </script>

    <div>
        <input type="submit" value="Submit"/>
    </div>
</form>

This is my form, when I search a bus through it, whatever date I give,it's showing me the bus from my database(searchiing by it's source point and destination_point), but I've inserted available days for the buses. i want to search the buses according to it's respective days. That means when I'm entering a date in my datepicker, it should search it's corresponding day from the database and show the result, if in that day, the bus is not available, it should not display any result.

search.php

<?php
    $s=mysql_query("SELECT * FROM  bus_detail where source_point='$_SESSION[source_point]' && destination_point='$_SESSION[destination]'");
    while($row=mysql_fetch_array($s))
    {
?>

<td><input name="bus_name" type="text" value="<?php echo $row['bus_name'];?>" class="input_box" />

解决方案

we really need to see your server side code and the data structure to determine this.

ideally you would want to capture the date range(s) then adjust your SQL statement to only return the values based on that.

$datepick would be your value from your form probably a cleaned $_POST['datepicke'];

this would make is from 12:00AM on the date till 12:00AM the next date so within one day

example SQL: "SELECT * FROM bus WHERE departure => $datepick AND departure <= DATE_ADD($datepick, INTERVAL 1 DAY)"

hope that helps

这篇关于从日期选择器逐日搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆