How to make a top 5 in php

Asked

Viewed 76 times

-1

Hello, I wanted to make a Top 5 in php with the 5 most featured users, How can I do this?

Table is tb_user and column is Referrals.

Ex:

1º José - Has 5 Nominees
2º Mario - Has 2 nominees
3º José - Has 1 Nominee
4º José - Has 1 Nominee
5º José - Has 1 Nominee

  • Supplement your question with information on how, for example, your database is modeled. So you can try to suggest a solution.

1 answer

1

Boas, I do not understand very well the question, nor what you have already done, nor what type of database... But I will try to give some tips: After connecting to the database (I suppose you already have) you need to query (Here in Mysql)... I think what you want is:

$query="SELECT * FROM tb_user ORDER_BY referrals DESC"

Then you need to query:

$result=mysqli_query($link, $query);

And collect the result

 $count=1;

 while ($pessoa = mysqli_fetch_assoc($result)) {
   echo $count."º ".$pessoa["nome"]." - Tem ".$pessoa["referrals"]." indicados.<br>";
   $count++;
  }

Well, if I don’t have any syntax error (I haven’t used this in a while), I guess this is it!

Browser other questions tagged

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