To obtain the data, it does not work for me by making the assoc to the first login_token_select variable, but I have to repeat that line, that is, do the query again so that the assoc works, is there no way to do it without having to repeat the code?
$login_token_select = mysqli_query($base,"SELECT * FROM $users WHERE token = '$login_token'");
if (mysqli_fetch_row($login_token_select) > 0 && mysqli_fetch_row($login_token_select) < 1) {
// TENGO QUE REPETIRLA AQUÍ PARA QUE OBTENGA LOS DATOS
//$login_token_select = mysqli_query($base,"SELECT * FROM $users WHERE token = '$login_token'");
while ($login_token_get = mysqli_fetch_assoc($login_token_select)) {
echo "Hola ".$login_token_get['name']."<br>Naciste el ".$login_token_get['birthday'];
}
} else{}
your script is also wrong, I would use the method
num_rows
to validate if there are records:you must not use
mysqli_fetch_assoc
to validate; since this method returns the advance of the rows that your query has returned each time you execute it.Documentation related to num_rows
The function
mysqli_query()
returns a database access resource with a pointer to get the results and advances each time you usemysqli_fetch_*()
; in fact, I'm surprised that it works for you, because it should give an error when reaching the end of the result set, because the functionsmysqli_fetch_*()
return an array or false if no records were obtained in the query or the pointer reached the end; Y:Then in the loop you have to execute the query again because the pointer has already reached the end. If the token is unique, you simply have to parse the result of
mysql_fetch_assoc()
, if it is false, no matches were obtained:If there can be duplicate tokens, then you have a problem with your project design.