【发布时间】:2019-11-05 07:15:27
【问题描述】:
问题是我试图在 2 种日期(date_open 和 date_close)之间搜索记录
+---------+------------------+-------+-----------+------------+------------+
| File ID | File Desc. |Return | Open Date | Close Date | Open/Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/4 | 1 - Test 1 400/4 | |2016-02-12 | 2018-03-26 | Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/1 | 5 - Test 5 400/1 | |2016-01-11 | 2018-02-23 | Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/1 | 2 - Test 2 400/1 | |2015-03-16 | 2017-05-20 | Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/2 | 3 - Test 3 400/2 | |2015-05-15 | 2017-02-11 | Close |
+---------+------------------+-------+-----------+------------+------------+
<label>File ID</label>
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $strKeyword;?>" placeholder="Ex. 400/1">
<label>File Description</label>
<input name="txtKeyword2" type="text" id="txtKeyword2" value="<?php echo $strKeyword2;?>" placeholder="Ex. 10 - Pelbagai Surat Menyurat Ansuran Cukai Tanah">
<label>Date Open from </label>
<input name="txtKeyword3" type="date" id="txtKeyword3" value="<?php echo $strKeyword3;?>">
<label>To </label>
<input name="txtKeyword4" type="date" id="txtKeyword4" value="<?php echo $strKeyword4;?>">
<br />
<label>Date Close from </label>
<input name="txtKeyword5" type="date" id="txtKeyword5" value="<?php echo $strKeyword5;?>">
<label>To </label>
<input name="txtKeyword6" type="date" id="txtKeyword6" value="<?php echo $strKeyword6;?>">
<br />
<label>Status</label>
<input name="txtKeyword7" type="text" id="txtKeyword7" value="<?php echo $strKeyword7;?>">
<br />
<input class="search" type="submit" value="Search">
我的日期输入是这样的
开放日期:2016-01-11 致:2016-02-12 截止日期:2018-02-23 致:2018-03-26
假设返回这样的列表
+---------+------------------+-------+-----------+------------+------------+
| File ID | File Desc. |Return | Open Date | Close Date | Open/Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/4 | 1 - Test 1 400/4 | |2016-02-12 | 2018-03-26 | Close |
+---------+------------------+-------+-----------+------------+------------+
| 400/1 | 5 - Test 5 400/1 | |2016-01-11 | 2018-02-23 | Close |
+---------+------------------+-------+-----------+------------+------------+
但它根本不返回任何值,也不会弹出错误
+---------+------------------+-------+-----------+------------+------------+
| File ID | File Desc. |Return | Open Date | Close Date | Open/Close |
+---------+------------------+-------+-----------+------------+------------+
我的搜索代码是这样的
$sql = "SELECT * FROM file_list WHERE
CONCAT(`file_no`) LIKE '%".$strKeyword."%'
AND CONCAT(`file_desc`) LIKE '%".$strKeyword2."%'
AND CONCAT(`date_open`) LIKE ((CONCAT(`date_open`) >= '%".$strKeyword3."%' AND CONCAT(`date_close`) <= '%".$strKeyword4."%'))
AND CONCAT(`date_close`) LIKE ((CONCAT(`date_close`) >= '%".$strKeyword5."%' AND CONCAT(`date_close`) <= '%".$strKeyword6."%'))
AND CONCAT(`open_close`) LIKE '%".$strKeyword7."%'";
$query = mysqli_query($dbConn,$sql);
【问题讨论】:
-
你需要学习如何使用参数而不是修改查询字符串。