【发布时间】:2016-10-09 05:46:34
【问题描述】:
我想从这个表中选择 * 数据只是为了根据我选择的过滤器显示所有内容。
我的桌子:
tbl_reservation
res_id | trans_code | status | order_type | type_of_order | date_ordered
------ | -----------|----------|--------------|-------------------|-------------
1 | 111-111 |Delivered | For Delivery | Online Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
2 | 111-112 |Delivered | For Pick-up | Online Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
3 | 111-113 |Cancelled | For Delivery | Online Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
4 | 111-114 | | For Purchase | Online Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
5 | 111-115 | | For Pick-up | Walkin Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
6 | 111-116 | | For Purchase | Walkin Transaction|2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
7 | 111-117 |Delivered | For Pick-up | Walin Transaction |2016-10-09
------ | -----------|----------|--------------|-------------------|-------------
8 | 111-118 |Delivered | For Delivery | Online Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
9 | 111-119 |Delivered | For Pick-up | Online Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
10 | 111-110 |Cancelled | For Delivery | Online Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
11 | 111-100 | | For Purchase | Online Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
12 | 111-101 | | For Pick-up | Walkin Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
13 | 111-102 | | For Purchase | Walkin Transaction|2016-10-08
------ | -----------|----------|--------------|-------------------|-------------
14 | 111-103 |Delivered | For Pick-up | Walin Transaction |2016-10-08
我的表格:
<form method="post" action="">
<select name="filter">
<option value="Today">Filter Data for today</option>
<option value="Yesterday">Filter Data for yesterday</option>
</select>
<input type="submit" value="Filter"/>
</form>
我的 PHP 代码和关于获取过滤器的示例查询
<?php
//inclue db connection
if(isset($_POST["filter"])){
$get_filter = $_POST["filter"];
if($filter == "Today"){
$sql = mysql_query("SELECT * FROM tbl_reservation WHERE status = 'Delivered' OR status = 'Cancelled' OR status = '' AND DATE(date_ordered) = DATE(now()) ");
}elseif($filter == "Yesterday"){
$sql = mysql_query("SELECT * FROM tbl_reservation WHERE status = 'Delivered' OR status = 'Cancelled' OR status = '' AND DATE(date_ordered) = DATE(now())-1 ");
}
//THEN DISPLAY ALL IN VARIABLE USING WHILE LOOP AS mysql_fetch_array
//Display data here
//..
//..
//..
?>
日期顺序 = 2016-10-09 [今天]
订单日期 = 2016-10-08 [昨天]
没有错误。
当我选择今天的过滤时..它会显示所有数据以及昨天的数据
但是当我选择昨天时..它会显示所有数据以及今天的数据
我希望更正数据查询。有人可以帮忙吗?谢谢。
【问题讨论】: