Query table row and "ranking"

0

I'm creating a series of profiles, and I want to create a sort of ranking based on the number of visits .

I already created the script to add visits and everything is already right in the users table.

User_id|User_cover|User_name|User_content|User_pais|User_facebook|User_date|**User_views** 

The User_views adds to each view. I happen to want to show the result of the query and calculate by the column User_views to position in the table that this user is. Returning a number for display in HTML.

Can I do this without script or will I have to adapt? And if I have to do that, what logic do I need to execute?

    
asked by anonymous 03.02.2015 / 12:08

1 answer

1

You can bring this column already from SQL. Just create a temporary column with auto increment and make an order by user_views. Here's an example in MySql:

SELECT
  (@count := @count + 1) AS ranking,
  users.*
FROM users
  CROSS JOIN (SELECT @count := 0) AS dummy
ORDER BY users.user_views DESC;
    
03.02.2015 / 12:27