我有一个从mysql数据库中提取数据的php页面。我选择了月份和年份,它应该显示我需要的数据,但当年份更改为2015年时,我发现它只显示2014年的数据。这是代码和URL字符串
$colname_Recordset1 = "-1";
if (isset($_GET['Month'])) {
$colname_Recordset1 = $_GET['Month'];
}
mysql_select_db($database_hk, $hk);<br>
$query_Recordset1 = sprintf("SELECT * FROM inventory WHERE `Month` = %s", GetSQLValueString($colname_Recordset1, "text"));<br>
$Recordset1 = mysql_query($query_Recordset1, $hk) or die(mysql_error());
<br>$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
我能够手动执行此操作的唯一方法是将代码更改为此<
$query_Recordset1 = sprintf("SELECT * FROM inventory WHERE `Month` = %s AND year = '2015'", GetSQLValueString($colname_Recordset1, "text"));
我希望通过2个选择下拉菜单来设置月份和年份的值
<form method="get" name="form">
<table width="70%" border="0" align="left" cellpadding="0" cellspacing="0">
<caption>
<br>
</caption>
<tr>
<th colspan="4" align="center" scope="col"><h3>Inventory
<label for="month">Month:</label>
<select name="Month" id="Month">
<option>Select</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<label for="year">Select:</label>
<select name="year" id="year">
<option>Year</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
<input type="submit" name="submit" id="submit" value="View">
</table>
按下查看按钮后的URL是 example.com/inventory_view.php?Month=January&year=2015&submit=View
我希望你能提供帮助 感谢
答案 0 :(得分:0)
你自己给出了答案。如果您没有通过年份,则无论年份如何,您都会获得特定月份的所有数据。所以也抓住你的$_GET
变量的年份并像你一样扩展你的查询,但只是像月份那样变量。