如何将外键数据添加到主键数据并显示它

时间:2013-08-26 17:42:08

标签: php mysql

连接

<?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>
  1. 我的Dept_Desp是表'department'

  2. 中的数据
  3. 仅显示部门名称的第一个数据,无法显示真实的

1 个答案:

答案 0 :(得分:0)

select * from Employee left join department on employee.department_id = department.department_id where Emp_ID =$id

这样的东西......也读了mysqli或pdo ....你的db方法非常不安全。