-1
I have the following array:
array(2) {
[0]=>
array(2) {
["username"]=>
string(6) "User01"
["quant"]=>
string(1) "6"
}
[1]=>
array(2) {
["username"]=>
string(5) "Teste"
["quant"]=>
string(1) "3"
}
[2]=>
array(2) {
["username"]=>
string(5) "xxXxx"
["quant"]=>
string(1) "5"
}
}
How do I take all fields "username" and list, "User01, Test, xxxxx"
I found a function that lists only by array id:
$resultado[0][username];
echo $resultado;
User01
I only printed the set value la[0], but I want you to print all usernames.
Here is the full code, but I only printed the regitro ulitmo.
$sql = 'SELECT username, COUNT(*) AS quant FROM acessos WHERE hora > :hora GROUP BY username';
$statement = $pdo->prepare($sql);
$statement->bindValue(":hora", date('H:i:s', strtotime('-1 minutes')));
$statement->execute();
$resultado = $statement->fetchAll(PDO::FETCH_ASSOC);
//var_dump($resultado);
foreach($resultado as $item){
$dados = $item["username"];
}
echo "-> " . $dados;
-> xxXxx
If you read my answer, you must have realized that the
echo
has to stay within the loop.– Jéf Bueno
It worked right, I just wanted to know which format to be "User01, Test, xxxxx" Thanks for the patience :)
– João
Open another question with this specific problem, please. By the way, if the answer has solved your problem, you can tag it using the ✓ on the left side of the answer.
– Jéf Bueno