dongwen5351 2015-06-29 07:10
浏览 14
已采纳

如何使用PHP在MySQL表上使用内连接?

I have two tables like this:

Employee

EmployeeID  EmployeeName
1234        Jessica
1235        Tiffany
1236        Kayla
1237        Jackson
1238        Junior
1239        Ray
1240        Raymond

And...

Form

IDForm Form_EmployeeID Content AgreementBy  Verificationby  Validateby  receiver

1      1234            abcde   1235         1236            1237        1240

2      1238            dcbe    1235         1239            1237        1240 

The problem is, I want to display a data like this:

I have tried use this code:

$id=$_GET['id'];

$sql=mysql_query("SELECT Employee.*, Form.*
                        FROM Form
                        INNER JOIN Employee ON Form.Form_EmployeeID= Employee.EmployeeID
                        where Form.FormID = '$id'") or die(mysql_error()); $data=mysql_fetch_array($sql);

But the data appears just like this:

Form ID        : 1
Employee Name  : Jessica
Content        : abcde
Agreement By   : 
Verification By: 
Validate By    : 
Received By    : 

or like this:

 Form ID        : 1
Employee Name  : Jessica
Content        : abcde
Agreement By   : 1235
Verification By: 1236
Validate By    : 1237
Received By    : 1240

May I know where is the mistake?

  • 写回答

2条回答 默认 最新

  • dontoften8899 2015-06-29 07:25
    关注

    Your Query something like this...

    SELECT Form.*, 
        a.EmployeeName as employee_name,
        b.EmployeeName as agreement_by,
        c.EmployeeName as verification_by,      
        d.EmployeeName as validate_by,
        e.EmployeeName as receiver_by
                        FROM Form
                        LEFT JOIN Employee a ON Form.Form_EmployeeID= a.EmployeeID
                        LEFT JOIN Employee b ON Form.AgreementBy= b.EmployeeID
                        LEFT JOIN Employee c ON Form.Verificationby= c.EmployeeID
                        LEFT JOIN Employee d ON Form.Validateby= d.EmployeeID
                        LEFT JOIN Employee e ON Form.receiver= e.EmployeeID
                        where Form.FormID = '$id'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘