christianilvi
christianilvi

Reputation: 13

MySql - list all users and order by logged in user

I have a database table with all system users and I would like to list all users however the first in the select query must be the user which is the currently logged in user.

For example: say I have 7 users registered and the currently logged in user is 'bob', then when I call the select statement to list the users it would look like:

bob
other_user
other_user
other_user
other_user
other_user
other_user

The tbl_user columns
user_id
user_name
user_pass
user_email
user_gender
user_profilepic
forgotten_answer
log_in

Any help is appreciated. Thank you!

Current select statement is:

SELECT * FROM tbl_user

which basically selects all users unordered

Upvotes: 0

Views: 496

Answers (1)

flwd
flwd

Reputation: 613

This post answers what you are trying to do.

In your case try using SELECT * FROM tbl_user ORDER BY FIELD (user_name, "bob") DESC

"bob" would be replaced by whatever user is logged in but how you do that depends on your implementation.

Upvotes: 1

Related Questions