Know result of count () in query

0

I have the following query in pdo:

$ranking = $pdo->query("SELECT * FROM usuarios GROUP BY moedas ORDER BY count(moedas) DESC LIMIT 3");

I use this to make a ranking to know users with more coins. However, I am using a second query with rowCount () to know the amount of currencies of the listed user, would it be possible to extract the count value of that first query (quoted in the post)?

    
asked by anonymous 29.06.2017 / 05:59

1 answer

1

Yes, it is possible. See the example:

 $results= "
 SELECT p1.*, aa.moedas AS numbers
 FROM usuarios aa
 ORDER BY aa.moedas * 1 DESC
 DESC LIMIT 3
 ";

$stmt = $pdocon->prepare($results);
$stmt->execute();
while($row = $stmt->fetch()) {
echo $row["numbers"];
}
    
29.06.2017 / 06:06