我尝试选择特定员工的请求数据,但我没有得到任何东西。请帮助我。
这是第一页的代码。我从列表中选择了员工。
<select name="emp_id">
<?php
$emp_id = $_SESSION['emp_id'];
$query= "SELECT emp_id FROM request";
$result = mysql_query($query);
if(!$result)
{die("Query got problem").(mysql_error());}
else
{
while($row = mysql_fetch_assoc( $result )) {
echo "<option>".$row['emp_id']."</option>";}
echo "</select>";
}
?>
这是第二页的代码
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("employee_transfare",$con);
$query="select employee.f_name, employee.emp_id, request.from request.to, request.description, request.date from employee,equest where employee.emp_id=$_POST[emp_id] and employee.emp_id= request.emp_id" ;
$result = mysql_query($query);
{
echo "<table border='1'>";
echo "<tr> <th>Employee Name</th><th>ID</th><th>Current Department</th> <th>Requested Department</th> <th>Reason</th> <th>date</th> </tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo $row['f_name'];
echo "</td><td>";
echo $row['emp_id'];
echo "</td><td>";
echo $row['from'];
echo "</td><td>";
echo $row['to'];
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
echo $row['date'];
echo "</td></tr>";
}
echo "</table>";
}
?>
答案 0 :(得分:0)
我看到第一个错误:
echo "<option>".$row['emp_id']."</option>";
应该是:
echo '<option value="'.$row['emp_id'].'">'.$row['emp_id'].'</option>';
下一个可能的问题:
$query="select employee.f_name, employee.emp_id, request.from request.to, request.description, request.date from employee,equest where employee.emp_id=$_POST[emp_id] and employee.emp_id= request.emp_id" ;
应该是:
$query='select employee.f_name, employee.emp_id, request.from request.to, request.description, request.date
from employee,request
where employee.emp_id='.intval($_REQUEST['emp_id'], 10).' and employee.emp_id=request.emp_id';
仅针对调试错误,您也可以更改:
$result = mysql_query($query);
到
$result = mysql_query($query) or die(mysql_error());