I
I
Ilya Beloborodov2015-10-26 17:32:33
MySQL
Ilya Beloborodov, 2015-10-26 17:32:33

How to create a request?

There is a table of users in which, for example, 261 users
There is a page on which these users are displayed, they are sorted by id_user ASCand broken into pages (10 users per page)
Let's say my id_user=32, and when I go to the users page, I want to see myself on page 3 and second in a row.
something like this:
31. someone there
32. me
33. someone there
34. someone there
35. someone there
36. someone there
37. someone there
38. someone there
39 .someone there 40.someone
there

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Kovalsky, 2015-10-26
@dmitryKovalskiy

select ROW_NUMBER() OVER(ORDER BY id_user asc), ...over fields FROM MyTable

V
Vladimir Martyanov, 2015-10-26
@vilgeforce

SET @n=0;SELECT @n:[email protected]+1 AS number, user FROM users ORDER BY user_id; - Something like that.

F
faustxp, 2015-10-26
@faustxp

SELECT id_user, name_user 
  FROM tbl
 WHERE id_user > (
                    SELECT trnnc(id_user, -1) 
                      FROM tbl
                     WHERE name_user = :user_name
                  )
   AND  id_user <=  (
                      SELECT trnnc(id_user, -1)  + 10
                        FROM tbl
                       WHERE name_user = :user_name
                    )
 ORDER BY id_user;

N
nozzy, 2015-11-02
@nozzy

SELECT (@row:[email protected]+1) AS ROW, id
FROM Users
,(SELECT  @row := 0) r   
order by ID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question