I have a database with two tables, related to each other by ID. The T1 contains the entire record of a primary user, and T2 contains alternative users linked to the main user ID.
What I need to do is that when an alternate user logs in, the TOKEN
of the alternate user is loaded instead of the TOKEN
of the main user, in order to automatically register the User code that started session.
Table 1 main user
id | usuario | password | token |
-----------------------------------
1 | Andres | ***** | e12A1 |
-----------------------------------
2 | Maria | ***** | HJb71 |
-----------------------------------
Table 2 alternative users
id | usuario | password | token | id_ppl |
--------------------------------------------
1 | Juana | ***** | | 1 |
--------------------------------------------
2 | Martin | ***** | | 1 |
--------------------------------------------
PHP = > Here I need to replace the token of the user ppl with the token of the alternative user.
$stmt = $conn->prepare("SELECT T1.* 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);
$stmt->fetch();
$user = array(
'id' => $id,
'usuario' => $usuario,
'token' => $token
);
My attempt was to do something like this:
$stmt = $conn->prepare("SELECT T1.*
(SELECT T1.token FROM escolar AS T1 LEFT OUTER JOIN users_extra AS T2 ON T1.token = T2.token) AS token_alt
FROM escolar AS T1 LEFT OUTER JOIN users_extra AS T2 ON T1.id = T2.id_ppl");
But I did not know how to continue, I'm learning PHP I'm a novice , and I thought that maybe when I get the alternative token, I could replace it with the main token.
Thanks for the help