当表列连接两次时,从mySQL回显数据

I am trying to echo both the employee name and manager name

SQL QUERY:

SELECT * 
FROM `form` 
INNER JOIN `emp` AS employee
ON `form`.emp_ID = employee.emp_ID
INNER JOIN `emp` AS manager
ON `form`.manager_ID = manager.emp_ID

ECHO:

while($row = $result->fetch_assoc()){
echo $row['emp_name']; 
}

Always outputs the managers name.

have tried the following:

$row['employee.emp_name']
$row['employee']['emp_name']

which all don't work.

any help is appreciated

When the columns have the same name, their values will overlap when retrieving by fetch_assoc(). You can either use fetch_array() and reference the columns by numeric index (not recommended with SELECT *, since you can't easily guarantee the order of columns), or you will have to list the column names explicitly and alias them. For example:

SELECT emp.emp_name emp_emp_name, manager.emp_name manager_emp_name, ...

This would give you separate distinctly named fields in the result, that you could then access from what fetch_assoc() returns.