我想根据下拉选择值编写SQL查询。基于下拉选择的SQL查询
例如,如果管理员选择今天,那么SQL查询应该只获得今天的记录等等。
HTML
<select name="report_date">
<option value="Today">Today</option>
<option value="Yesterday">Yesterday</option>
<option value="Last7Days">Last 7 Days</option>
<option value="This Week">This Week</option>
<option value="LastWeek">Last Week</option>
<option value="ThisMonth">This Month</option>
<option value="LastMonth">Last Month</option>
<option value="ThisYear">This Year</option>
<option value="LastYear">Last Year</option>
<option value="AllTime">All Time</option>
</select>
<input type="text" name="product_name"/>
PHP
$fixedrange = $_GET['report_date'];
$pname= $_GET['product_name'];
if($fixedrange=="Today"){
$today = date('Y-m-d');
$fixeddate = 'OR o.`custom_date`='. $today;
}
SQL查询
SELECT *
FROM order_items AS oi
INNER JOIN orders o ON o.id=oi.`order_id`
WHERE oi.`product_name` LIKE '%$pname%' $fixeddate
AND o.status = '1'
ORDER BY o.custom_date DESC
的问题是,所有的记录今天的点击时显示? –
哪个是o.'custom_date'列的类型? – scaisEdge
'custom_date'是日期列类型 –