我有一个搜索表单,用于根据输入的日期获取记录,它运行完美,但现在我正在尝试实现一个功能,我可以从特定日期搜索到另一个,我该如何去做。
这就是我试过的
<form class="form-horizontal" action="date_policy.php" method="post" name="form1" id="form1">
<div class="control-group">
<label class="control-label" for="input Date"><span class="asasa">*</span> Date:</label>
<div class="controls">
<input type="text" name="date" value="" size="32" id="input insured Date" placeholder="e.g 12-5-2014" />
</div>
</div>
<p align="center">
<input type="submit" class="btn btn-mini btn-primary" value="Search" /></p>
</form>
和我的查询代码段
mysql_select_db($database_kbl, $kbl);
$query_cert = sprintf("SELECT * FROM transactions WHERE Date = %s", GetSQLValueString($colname_cert, "text"));
$cert = mysql_query($query_cert, $kbl) or die(mysql_error());
$row_cert = mysql_fetch_assoc($cert);
$totalRows_cert = mysql_num_rows($cert);
答案 0 :(得分:0)
SELECT语句中的BETWEEN怎么样?像这样:
$query_cert = sprintf("SELECT * FROM transactions WHERE Date BETWEEN %s AND %s", GetSQLValueString($colname_cert, "text"), GetSQLValueString($mySecondDateField, "text"));
答案 1 :(得分:0)
好的,因为谷歌不是你的朋友。
<form class="form-horizontal" action="date_policy.php" method="post" name="form1" id="form1">
<div class="control-group">
<label class="control-label" for="input Date"><span class="asasa">*</span>Start Date:</label>
<div class="controls">
<input type="text" name="startdate" value="" size="32" id="input insured Date" placeholder="e.g 12-5-2014" />
</div>
<label class="control-label" for="input Date"><span class="asasa">*</span>End Date:</label>
<div class="controls">
<input type="text" name="enddate" value="" size="32" id="input insured Date" placeholder="e.g 12-5-2014" />
</div>
</div>
<p align="center">
<input type="submit" class="btn btn-mini btn-primary" value="Search" /></p>
</form>
并且SQL变为(注意我删除了你的解析函数,因为我不知道它是如何工作的)
mysql_select_db($database_kbl, $kbl);
$query_cert = "SELECT * FROM transactions WHERE Date BETWEEN '".$_POST['startdate']."' AND '".$_POST['enddate']."' ";
$cert = mysql_query($query_cert, $kbl) or die(mysql_error());
$row_cert = mysql_fetch_assoc($cert);
$totalRows_cert = mysql_num_rows($cert);