I have to make a list of the daily reports made by commercial agents and office managers in a single list. The reports are stored in the PPR table which has an id_user (if it is saved by an administrative) and a id_agent (if the agent makes the report). The user and agent tables each have a user_id and a file_id respectively. The issue is that I have no way for the query to go well because both the USER and the AGENT have the same "name" and "surname" fields ... I get the reports but without the name. Putting LEFT JOIN in both I get the full list of reports but only the names of the agents,
<?php
$query = mysql_query("select * from ppr
LEFT JOIN users ON users.user_id = ppr.id_user
LEFT JOIN agent ON agent.agent_id = ppr.id_agent
ORDER BY id_ppr DESC") or die(mysql_error());
?>
AGENTS table
Id_agente | nombre | apellidos
USERS Table
Id_user | nombre | apellidos
REPORTS Table (PPR)
Id_reporte | Id_user | Id_agente | reporte
Example:
nombre apellidos | tipo | reporte
-----------------+-----------+-------
Jose Poveda | (agente) | Reporte del día 4 de marzo....
Vicente Pérez | (usuario) | Reporte del día 4 de marzo...