我目前在一个表单中有多个搜索字段,用户可以选择并选择要过滤的一个,在我添加日期范围之前一切正常。如果我单独添加日期范围而没有任何其他字段来过滤它,那么我知道这并不是我写错了查询。请帮我解决这个问题。谢谢!
这是有效的查询:(由于某种原因,SELECT * 不起作用,我必须输入我要显示的所有字段的名称)
它包括包含日期范围的表单部分。
<li class="form-line form-line-column" id="id_29">
<label class="form-label-top" id="label_29" for="input_30">
From Date:
</label>
<div id="cid_29" class="form-input-wide">
<input type="text" class="form-textbox validate" id="datepicker" name="from_date" size="10" />
</div>
</li>
<li class="form-line form-line-column" id="id_29">
<label class="form-label-top" id="label_29" for="input_8">
To Date:
</label>
<div id="cid_29" class="form-input-wide">
<input type="text" class="form-textbox validate" id="datepicker2" name="to_date" size="10" />
</div>
</li>
<?php
$sso = $_GET['sso'];
$assigned_to = $_GET['assigned_to'];
$case_status = $_GET['case_status'];
$startdate = $_GET['from_date'];
$enddate = $_GET['to_date'];
$subject = $_GET['subject'];
$sql = ("SELECT
id, sso, full_name, case_status, assigned_to, resolution,
description, updated, created, additional_notes, subject
FROM rmstable2
WHERE
sso LIKE '%$sso%' AND
case_status LIKE '%$case_status%' AND
assigned_to LIKE '%$assigned_to%' AND
subject LIKE '%$subject%'");
?>
这是我想要的查询:
<?php
$sql = ("SELECT
id, sso, full_name, case_status, assigned_to, resolution,
description, updated, created, additional_notes, subject
FROM rmstable2
WHERE
sso LIKE '%$sso%' AND
case_status LIKE '%$case_status%' AND
assigned_to LIKE '%$assigned_to%' AND
subject LIKE '%$subject%'
AND created >= '$startdate'
AND created <= '$enddate'");
?>