Know Count() output in query

Asked

Viewed 102 times

0

I have the following query on 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 coins of the user listed, it would be possible to extract the value of Count(coins) from this first query (quoted in the post)?

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"];
}
  • That’s not what I want friend, I need to know the value of COUNT(coins).

  • I edited the answer. You have to explain the structure of your table better.

  • And how do I show off?

  • I edited my answer again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.