开发者

fetching data from the inner join query

hello please help me out regarding this query ,I am fetching data from different table The problem i am facing is that in the table there are similar colum name like employee have and user has also name . The query work perfectly but i am wordering about how i can display this data as

$data["employee.name"]
$data["user.name"]

here is the query:

SELECT task.employee_id , task.user_id , task.service_id, user.name, 
       user.pic_path , employee.name ,employee.pic_path 
FROM task  
INNER JOIN employee ON employee.pno = task.employee_id  
INNER JOIN user ON user.pno 开发者_如何学编程= task.user_id 
INNER JOIN service ON service.service_id = task.service_id ";


SELECT user.name AS username, employee.name AS employeename

You get the point.


There are two steps:

  1. You need to define a column alias for at least one of the two columns in the SQL statement:

    SELECT t.employee_id, 
           t.user_id, 
           t.service_id, 
           u.name AS user_name, 
           u.pic_path, 
           e.name AS employee_name,
           e.pic_path 
      FROM TASK t
      JOIN EMPLOYEE e ON e.pno = t.employee_id  
      JOIN USER u ON ur.pno = t.user_id 
      JOIN SERVICE s ON s.service_id = t.service_id
    
  2. Then you need to update the PHP logic to use the column aliases:

    $empname = $data["employee_name"];
    $username = $data["user_name"];
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜