How to make a Top 5 in php [closed]

-1

Hello, I wanted to make a Top 5 in php with the top 5 users, how can I do this?

The table is tb_user and the column is referrals.

Ex:

1st José - It has 5 Indicated
2º Mario - You have 2 nominated
3º José - It has 1 Indicado
4º José - It has 1 Indicado
5º José - It has 1 Indicado

    
asked by anonymous 25.03.2015 / 23:13

1 answer

1

Good, I do not understand very well the question, what has already done or what type of database ... But I'll try to give some tips: After connecting to the database (I assume you already have it done) you need to do the 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 do not have any syntax errors (I have not used this for some time), I believe this is it!

    
26.03.2015 / 00:28