RESULT NOT FOUND IN QUERY WITH 3 TABLES
Hey guys i have 3 tables called
"ESPECIALITATS" (N) <------ (1) "TREBALLADORS" (1) --------> "USUARIS"
I have a web page with login so depends of grup , they users can see all or only to themselves.
EXAMPLES FOR OFICIAL USERS.
In the case of grup that can see all i use this code and its work. (This example is for INDETIFIED BY GROUP "OFICIAL").
SELECT tr.DNI, tr.Codics, tr.Nom, tr.Data_Naixement, tr.SS, tr.Direccio, tr.CP,
tr.Poblacio, tr.Telefon_casa, tr.Telefon_movil, tr.Rango, tr.Antiguitat_reconeguda, tr.N_personal,
tr.email, esp.Nom as especialitat, esp.Data_inici and esp.Data_fi
FROM
TREBALLADORS as tr
LEFT JOIN ESPECIALITATS as esp ON esp.DNI_Treballadors_Esp=tr.DNI
LEFT JOIN USUARIS as user ON user.DNI_Treballadors_Usuari=tr.DNI;
EXAMPLE FOR NORMAL USERS
The normal users only can see their own information.
If use this code, the user that in table "ESPECIALITATS" have not records, Cannot see the records from the table "TREBALLADORS" that have records.
"SELECT tr.DNI, tr.Codics, tr.Nom, tr.Data_Naixement, tr.SS, tr.Direccio, tr.CP,
tr.Poblacio, tr.Telefon_casa, tr.Telefon_movil, tr.Rango, tr.Antiguitat_reconeguda, tr.N_personal,
tr.email, esp.Nom as especialitat, esp.Data_inici and esp.Data_fi
FROM
USUARIS as user,
TREBALLADORS as tr,
ESPECIALITATS as esp
where user.DNI_Treballadors_Usuari=tr.DNI and esp.DNI_Treballadors_Esp=tr.DNI and (user.Usuari='".$_SESSION['Usuari']."')"
If use this code, the user can see all the dates from all and nulls but i want that the user can only see his own information.
$q = "SELECT tr.DNI, tr.Codics, tr.Nom, tr.Data_Naixement, tr.SS, tr.Direccio, tr.CP,
tr.Poblacio, tr.Telefon_casa, tr.Telefon_movil, tr.Rango, tr.Antiguitat_reconeguda, tr.N_personal,
tr.email, esp.Nom as especialitat, esp.Data_inici and esp.Data_fi
FROM
TREBALLADORS as tr
LEFT JOIN ESPECIALITATS as esp ON esp.DNI_Treballadors_Esp=tr.DNI
LEFT JOIN USUARIS as user ON user.DNI_Treballadors_Usuari=tr.DNI and (user.Usuari='".$_SESSION['Usuari']."')";
Any suggestions?