How can I select the user who logs in to show the name in php, table 1 is for the main users, and table 2 is for additional users, related to the main user by ID and ID_ppl
I need to show in php the username that starts the session. but only the main user shows me, although I login with an additional user, the additional username must be shown.
For example, I connect with ** Juana ** and in php they show me ** Andres **, the main user; when you should show me the name of Juana
Table 1 main users
id | usuario | password | token | nivel | estado |
----------------------------------------------------
1 | Andres | ***** | e12A1 | 1 | on |
----------------------------------------------------
Table 2 additional users
id | usuario | password | token | id_ppl | nivel | estado |
-------------------------------------------------------------
1 | Juana | ***** | | 1 | 2 | on |
-------------------------------------------------------------
2 | Martin | ***** | | 1 | 2 | off |
-------------------------------------------------------------
Php query
$stmt = $conn->prepare("SELECT T1.id, T1.usuario, T1.token, T1.nivel, T1.estado FROM escolar AS T1 LEFT OUTER JOIN users_extra AS T2 ON T1.id = T2.id_ppl");
$stmt->bind_param("ss",$usuario, $password);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($id, $usuario, $token, $nivel, $estado);
$stmt->fetch();
$user = array(
'id' => $id,
'usuario' => $usuario,
'token' => $token,
'nivel' => $nivel,
'estado' => $estado
);