我在這裏是一個下拉菜單,按年份和月份從數據庫中選擇記錄。這工作正確得到年,只有1個月。我需要的是將Januanry的所有內容按年份分配到六月份的記錄或七月至十二月。幫幫我?如果你想爲一個特定的月和年取的記錄,對日期字段使用month
和year
功能在年份和月份中獲取數據庫中的記錄
我的日期格式爲YYYY-MM-DD
<form id="form1" name="form1" action="<?php $_SERVER['PHP_SELF']?>" method="post">
<?php
$startYear = 2013;
$curYear = date('Y');
echo'<select name="year">';
foreach (range($startYear, $curYear) as $year) {
echo '<option>'.$year.'</option>';
}
echo'</select>';
echo'<select name="month">';
for ($x=1; $x<=12; $x++)
{
$val=strlen($x);
if($val==1)
{
echo '<option value="'.'0'.$x.'">'.'0'.$x.'</option>';
} else {
echo '<option value="'.$x.'">'.$x.'</option>';
}
}
echo'</select>';
?>
<input type="submit" name="date" value="date"/>
</form>
<?php
$year = $mysqli->real_escape_string($_POST["year"]);
$month = $mysqli->real_escape_string($_POST["month"]);
echo $year.'-'.$month;
$result1 = $mysqli->query("SELECT po_date, rfq, shop, nego, shop, po_number, counter FROM purchase_order WHERE po_date LIKE '$year-$month-__' GROUP BY counter ORDER BY po_date");
「po_date」字段的類型是什麼? –
[MySQL選擇日期範圍問題]的可能的重複(http://stackoverflow.com/questions/4897133/mysql-select-date-range-issue) –
@FezVrasta類型是日期 – user3097736