我正在尝试显示特定员工的离开历史,但是当我选择特定月份时,例如:我选择1月显示,而不是显示1月的历史,它显示今年的所有历史记录。我的代码有什么问题吗?下面是我的代码:
<?php
echo 'View the application history by :<select name="date">
<option value="january" selected="selected">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>';
echo'</select>';
$value = 'value';
if($value=='january')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-01-01' and Date_Apply<'2013-01-31'");
}
else if($value=='february')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-02-01' and Date_Apply<'2013-02-28'");
}
else if($value=='march')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-03-01' and Date_Apply<'2013-03-31'");
}
else if($value=='april')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-04-01' and Date_Apply<'2013-04-30'");
}
else if($value=='may')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-05-01' and Date_Apply<'2013-05-31'");
}
else if($value=='june')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-06-01' and Date_Apply<'2013-06-30'");
}
else if($value=='july')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-07-01' and Date_Apply<'2013-07-31'");
}
else if($value=='august')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-08-01' and Date_Apply<'2013-08-31'");
}
else if($value=='september')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-09-01' and Date_Apply<'2013-09-30'");
}
else if($value=='october')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-10-01' and Date_Apply<'2013-10-31'");
}
else if($value=='november')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-11-01' and Date_Apply<'2013-11-30'");
}
else if($value=='december')
{
$check_user=mysql_query("select*from employee e, `leave` l where e.emp_id = l.emp_id and l.Emp_ID='".$aid."' and Date_Apply >='2013-12-01' and Date_Apply<'2013-12-31'");
}
echo "<table border='1'>";
echo "<tr>";
echo "<th>Leave No</th>";
echo "<th>Leave Start</th>";
echo "<th>Leave End</th>";
echo "<th>Date Apply</th>";
echo "<th>Duration</th>";
echo "<th>Leave Type</th>";
echo "<th>Leave Reason</th>";
echo "<th>Status</th>";
$counter = 0;
while($rows = mysql_fetch_assoc($check_user))
{
echo"<tr>";
echo"<td>" . $rows['Leave_ID'] . "</td>";
echo"<td>" . $rows['Leave_Start'] . "</td>";
echo"<td>" . $rows['Leave_End'] . "</td>";
echo"<td>" . $rows['Date_Apply'] . "</td>";
echo"<td>" . $rows['Duration'] . "</td>";
echo"<td>" . $rows['Leave_Type'] . "</td>";
echo"<td>" . $rows['Leave_Reason'] . "</td>";
echo"<td>" . $rows['Status'] . "</td>";
$counter++;
}
echo "</table>";
?>
答案 0 :(得分:2)
是。您将$ value的值设置为'value'。然后检查该变量是否包含月份的名称。那是不可能的。另外:月份的名称将在名为$ date的变量中...如果您从选择框中读取它(并将其放在名为$ date的变量中)。除此之外,选择框不会做任何事情,因为它需要在表单标签内。 (并提交按钮或其他东西来提交该表格..然后读出来(通过使用GET)并将其放入$ date变量..虽然我会使用不同的名称,以确保名称是唯一的.. 。)