tags:

views:

24

answers:

3

I have some users listed below in an order:

user1 user2 user3 user4 user5

This is just a simple list, sorted according to age.

Now a new user (user6) comes in, and according to the sorting, he fits after user 2, so the order becomes like:

user1 user2 user6 user3 user4 user5

Now I want to know at which position it is. For example it is on place3. How can i find its position when a new user comes in the list?? Please tell any general way? there is no any database etc, just a logic question.

A: 

What does this have to do with MySQL?

Use array_search($myuser, $users);

See http://us2.php.net/manual/en/function.array-search.php .

Borealid
A: 
liar
Clever. Nice username.
Borealid
A: 

May be something like this:

SELECT count(b.id)+1 row_pos
FROM users a, users b
WHERE
    a.name = 'user6'
    AND a.age > b.age

Thus it shows position of your row

okhomenko