在我的情況,我有MySQL中的日期字段,我通過使用下面的代碼來獲取值變量。這是正確的,當我查詢完整的日期,如「08-28-1989」。查詢月,日和年中的日期
MySQL的:
SELECT COUNT(*)
FROM content
where dateReceived='{$approved_date}'
and description='{$description}'
PHP:
$approved_year = $_POST["approved_year"];
$approved_month = $_POST["approved_month"];
$approved_day = $_POST["approved_day"];
$approved_dt = strtotime($approved_year."-".$approved_month."-".$approved_day);
$approved_date = date("Y-m-d",$approved_dt);
我怎樣才能讓更多的動態,如果我說,用戶只需輸入 「08」(月只),那麼它會顯示所有記錄在那個月不分日日。或者,用戶只需輸入月份和年份,並將其查詢到我的數據庫。
這裏是我的HTML也:
<p>
Date Approved
<select name="approved_month">
<?php
$month = array(" ","January","February","March","April",
"May","June","July","August",
"Septembe","October","November","December");
for($x=0;$x<12;$x++){
echo "<option value=\"".$x."\">".$month[$x]."</option>";
}
?>
</select>
<input type="text" name="approved_day" value="" size="2" />
<input type="text" name="approved_year" value="" size="10" />
</p>
向我們顯示您正在用於按日期獲取結果的數據庫查詢。 –