As commented by Mr Anderson, mysqli_fetch_assoc
does not do what you are expecting, and the result you have obtained is absolutely correct (comes one at a time, and obviously is the first).
Mr Sam’s reply has an example of how to use the loop
.
If you want to get all users at once, you should prefer the função mysqli_fetch_all
:
$checkEmail = "SELECT email ";
$checkEmail .= "FROM usuariospf ";
$checkEmail .= "WHERE usuarioID <> 2";
$resultEmail = mysqli_query($connection, $checkEmail);
if(!$resultEmail){
die('Erro ao fazer a consulta!');
}
$users = mysqli_fetch_all($resultEmail,MYSQLI_ASSOC);
print_r($users);
Handbook:
https://www.php.net/manual/en/mysqli-result.fetch-all.php
Note the use of the option MYSQLI_ASSOC
for associative result instead of numerical.
Compare with the fetch-assoc
https://www.php.net/manual/en/mysqli-result.fetch-assoc.php
If there is no function error, make sure your PHP is using the extension mysqlnd
. If not, try to use it this way:
$resultEmail->fetch_all(MYSQLI_ASSOC);
I took the opportunity to change your NOT IN
for WHERE usuarioID <> 2
. The IN
makes sense when you want to use a list of values, like WHERE usuarioID NOT IN (2, 3, 7)
Have you looked in the documentation what the function
mysqli_fetch_assoc
does? It seems that you are misusing it.– Woss
Not related to the problem itself, but it’s worth noting that IN makes sense when you have a list to compare. For a single value, just use the different sign
usuarioID <> 2
or evenNOT usuarioID = 2
https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html– Bacco