php - 如何在主键数据上添加外键数据并显示

标签 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. 仅显示部门名称的第一个数据,无法显示真实的数据

最佳答案

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/

相关文章:

php - Mysql命令按街道名称然后编号对地址进行排序

php - Laravel 在数组错误上调用成员函数 toArray()

php - 查询耗时 1781s -

java - Java EE 中的 Unicode 并将问号保存在数据库中

php - 如何在 for 循环内获取给定月份所有天的记录总数

php - 为了还是为了?

Mysql 查找字符串中的数字并按字符串中的数字过滤结果

mysql - 在具有最新版本的 Mac OS X 上安装旧版本的 MySQL 5.5

php - 修改PHP代码SocialEngine

php - 如何处理表单中的多次提交?