0
I am trying to make a ranking system, where the username and the score appear. I am doing as follows:
$select = $mysqli->query("select username, pontos from data order by pontos desc limit 10");
$row = $select->num_rows;
$get = $select->fetch_array();
$top_1 = $get[0];
$top_1_pontos = $get[1];
$top_2 = $get[2];
$top_2_pontos = $get[3];
Using an echo on $top_1
it displays the user name with the highest score.
Using an echo on $top_1_pontos
it displays the user’s score.
From the $top_1_pontos
he exhibits nothing else... what I did wrong?
What is the correct way to get the ranking searching all users and listing the top 10?
Mysql looks something like this:
INSERT INTO `data` (`id`,`username`,`pontos`) VALUES
(1,'Joao',9321),
(2,'Maria',151000),
(3,'Pedro',21201),
(4,'Jose',31252),
(5,'Antonio',131145),
(6,'Adriano',13211),
(7,'Marcelo',6897),
(8,'Juliana',53144);
How many records are in the table? You’ve tried print_r at $get to see everything it brings?
– Fabio Nader
You are just selecting the username and the points in your query, that is $get[2] you no longer have anything. It should have been an error
undefined index...
– Miguel
Hey, but then you asked to display only username and points, and nothing else... why didn’t you make a foreach() to list the records with the proper scores? You can paste your SQL here, and we set up a practical example
– Sr. André Baill
I edited with the data André, she is more or less that way.
– Raizant