php日期搜索框查询

时间:2012-09-18 14:59:30

标签: php jquery mysql search search-box

我在oscommerce上有一个订单页面,其中有一个搜索框,允许用户在购买之日过滤结果。

这里是用于显示搜索框的html标记,它使用jquery datepicker来选择日期:

<table border="0" align="right">
<tr><?php echo tep_draw_form('search_date_purchased', FILENAME_ORDERS, '', 'get'); ?>

<td class="smallText" align="right"><?php echo TEXT_ORDER_DATE;?>&nbsp;<input type="text" name="search_date_purchased" placeholder="Choose a Date" class="datepick"/></td>
</form>
</tr>
</table>

tep_draw_form的html输出为<form name="search_date_purchased" action="../admin/orders.php" method="get"> 这是运行搜索框查询的php端:

if (isset($HTTP_GET_VARS['search_date_purchased']) && !empty($HTTP_GET_VARS['search_date_purchased'])){




    if (strstr($HTTP_GET_VARS['search_date_purchased'],'-')){

        $search_date = explode("-", $HTTP_GET_VARS['search_date_purchased']);   

        $start_date = substr($search_date[0],6,4).'-'.substr($search_date[0],3,2).'-'.substr($search_date[0],0,2).' 17:00:00';

        $end_date = substr($search_date[1],6,4).'-'.substr($search_date[1],3,2).'-'.substr($search_date[1],0,2).' 17:00:00';    

        $search_query = "and (o.date_purchased >='".$start_date."' and o.date_purchased <='".$end_date."') ";


    }else{


    $start_date = substr($HTTP_GET_VARS['search_date_purchased'],6,4).'-'.substr($HTTP_GET_VARS['search_date_purchased'],3,2).'-'.substr($HTTP_GET_VARS['search_date_purchased'],0,2).' 17:00:00';

    $end_date = substr($HTTP_GET_VARS['search_date_purchased'],6,4).'-'.substr($HTTP_GET_VARS['search_date_purchased'],3,2).'-'.substr($HTTP_GET_VARS['search_date_purchased'],0,2).' 17:00:00';    

        $search_query = "and (o.date_purchased >='".$start_date."' and o.date_purchased <='".$end_date."') ";
    }

}else{
    $yesterday = date("Y-m-d",strtotime('-1 day')).' 17:00:00';
    $today = date("Y-m-d").' 17:00:00'; 
    $search_query = "and (o.date_purchased >='".$yesterday."' and o.date_purchased <='".$today."') ";

}

if (isset($HTTP_GET_VARS['cID'])) {


  $cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);
  $orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.customers_id, o.payment_method, o.date_purchased, o.franchise_id, o.last_modified, o.date_allocated, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$cID . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total'  " . $franchise_search . "order by orders_id DESC ";
} elseif (isset($HTTP_GET_VARS['status']) && is_numeric($HTTP_GET_VARS['status']) && ($HTTP_GET_VARS['status'] > 0)) {
  $status = tep_db_prepare_input($HTTP_GET_VARS['status']);
  $orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.franchise_id,o.date_purchased, o.last_modified, o.currency, o.currency_value, o.date_allocated, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total'  " . $franchise_search . "order by o.orders_id DESC ";
} else {
  $orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.date_purchased, o.franchise_id, o.last_modified, o.date_allocated, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total'  " . $search_query . " order by o.orders_id DESC";
}

目前它所做的只是显示输入框的值,以及在URL中搜索但未运行搜索的日期。关于为什么以及如何修复的任何想法?

0 个答案:

没有答案