0
I’m wearing this query to know a user’s feedback quantity:
$comentarios = $pdo->query("SELECT * FROM topicos_comentarios WHERE autor='".$ver['autor']."'")->rowCount();
However, I would like to know his position in the overall ranking, I did a test and managed to list all users and their positions with this code:
<?php
include 'assets/php/config.php';
$ranking = $pdo->query("SELECT * FROM topicos_comentarios GROUP BY autor ORDER BY count(autor) DESC");
$i = 1;
while($ver = $ranking->fetch(PDO::FETCH_ASSOC)){
$comentarios = $pdo->query("SELECT * FROM topicos_comentarios WHERE autor='".$ver['autor']."'")->rowCount();
?>
<?php echo $i; ?>°- <?php echo $ver['autor'];?> - <?php echo $comentarios; ?></br>
<?php ++$i; } ?>
But how could I get that position individually?
Returned the following errors: Warning: PDO::query(): SQLSTATE[42000]: Syntax error or access Violation: 1248 Every derived table must have its Own alias in C: Xamp htdocs aGabriel list.php on line 12 Fatal error: Call to a Member Function fetchAll() on a non-object in C:Xamp htdocs aGabriel list.php on line 14
– Paulo Sérgio Filho
looks like Mysql needs alias, so it should look like "SELECT Tc.author, Tc. FROM (SELECT Count(author) as n, author FROM topicos_comments Tc GROUP BY author ORDER BY n DESC) a" but I don’t have an easy Mysql to test here.
– Fábio Roberto Teodoro
It worked perfectly, thank you very much! D
– Paulo Sérgio Filho