连接
<?php
$host = "localhost";
$user = "root";
$password = "";
mysql_connect($host, $user, $password);
mysql_select_db("admin");
SESSION_START();
if($_SESSION["loggedin"]!="true")
header("location:login.php");
$id = $_REQUEST["Emp_ID"];
$test = mysql_query("select * from Employee inner join department where Emp_ID =$id");
$row = mysql_fetch_assoc($test);
?>
详细信息表格
<table align="left" border="0" width="700px" cellpadding="0" cellspacing="5px">
<tr>
<th>Name :</th>
<td><?php echo $row["Emp_Fname"];?></td>
</tr>
<tr>
<th>Handphone :</th>
<td><?php echo $row["ContactNo_HP"];?></td>
</tr>
<tr>
<th>Telephone :</th>
<td><?php echo $row["ContactNo_Home"];?></td>
</tr>
<tr>
<th>Address :</th>
<td><?php echo $row["Emp_Address"];?></td>
</tr>
<tr>
<th>Email :</th>
<td><?php echo $row["Emp_Email"];?></td>
</tr>
<tr>
<th>Department :</th>
<td><?php echo $row["Dept_Desp"];?></td>
</tr>
</table>
我的 Dept_Desp 是表“department”内的数据
仅显示部门名称的第一个数据,无法显示真实的数据
最佳答案
select * from Employee left join department on employee.department_id = department.department_id where Emp_ID =$id
类似这样的东西...还要阅读 mysqli 或 pdo...您的数据库方法非常不安全。
关于php - 如何在主键数据上添加外键数据并显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18449842/