这是我的OJT项目。我需要在DATE类型的MySQL数据库中搜索生日。我已经从1月到12月收到了查询。 12月到1月是问题所在。
到目前为止,这就是我所做的代码:
<?php
require 'connect.php';
?>
<?php
if(isset($_POST['birthday_from']) && isset($_POST['birthday_to'])){
$start_date=$_POST['birthday_from'];
$end_date=$_POST['birthday_to'];
//$s = strtolower($end_date);
$start_year = date('m-d', strtotime($start_date));
$end_year = date('m-d', strtotime($end_date));
$search_year = date('Y', strtotime($start_date));
$search_year2 = date('Y', strtotime($end_date));
$sql=" select * from members where (DATE_FORMAT(`birthday`, '%m-%d') BETWEEN '{$start_year}' AND '{$end_year}') order by DATE_FORMAT(`birthday`, '%m-%d') asc ";
$result = mysql_query($sql);
$num_row = mysql_num_rows($result);
if($num_row >= 1){
echo '<div class="alert alert-info" style="margin:auto;width:900px;"><b><center>BIRTHDAY RESULT</center></b></div>';
while($rows = mysql_fetch_array($result)){
$date = date('Y-m-d')-$rows['birthday'];
echo '<b><span style="margin-left:20px;">Name:</span></b> '.strtoupper($rows['firstname'].' '.$rows['middlename'].' '.$rows['lastname'].' '.$rows['suffix']).'<br/>';
echo '<b><span>Birthday:</span></b> '.$rows['birthday'].'<br/>';
echo '<b><span style="margin-left:30px;">Age: </span></b>'.$date.'<br/><br />';
}
}
}
?>
答案 0 :(得分:2)
答案 1 :(得分:0)
您似乎正在为BETWEEN
声明使用错误的变量。
BETWEEN '{$start_year}' AND '{$end_year}'
应该是:
BETWEEN '{$seach_year}' AND '{$search_year2}'