0
I have a database (Mysql) with about 100 registered clients and am creating a table (ranking) of purchases of these customers, I know that the bank creates an ID autoincrement, would like to put in this table only the first 20 customers who buy more products and then would have the number of placement in the ranking and the name, but I’m not getting it.
Hello Bacco, Valew by tip. I wanted to put to each customer selected from the bank the number from 1 to 20 in front. Ex. 1 - Joäo (Being that the ID in the BD is 33), 2 - Maria (Being that ID in the BD is 55) and so on until reaching the 20.
– Jorge Toledo
As Bacco himself recommended in another answer, you can include a counter in the query:
SELECT @linha := @linha + 1 AS contador, cliente FROM clientes ORDER BY totalcompras DESC LIMIT 20
.– bfavaretto
@Jorgetoledo came to see the answer that the bfavaretto indicated? It is more or less what you need?
– Bacco
And oh guys, Bacco, I already did and did: $query_clients = mysql_query ( "select * from clients " ); while ( $client = mysql_fetch_array ( $query_clients ) ) { $id_client = $client['id']; $name_client = $client['name']; if ($query_clients){ $sequence++; And it all worked out, thanks a lot for the help..
– Jorge Toledo