1

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.

1
  • @moustafa: Does this have anything to do with MySQL? Commented Jul 10, 2010 at 7:45

2 Answers 2

1

What does this have to do with MySQL?

Use array_search($myuser, $users);

See https://www.php.net/manual/en/function.array-search.php .

Sign up to request clarification or add additional context in comments.

1 Comment

Possibly array_search($myuser, $users) + 1 in this case (he seems to want the index + 1).
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.