0

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

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Is log_in column a bool value to specify whether user has Logged in or not? – Edwin Dijas Chiwona Jun 07 '19 at 17:03
  • Use "SELECT * FROM tbl_user ORDER BY last_access_time,user_status DESC" – ximewatch Jun 07 '19 at 17:10
  • My implementation is basically a list of users who are registered and log_in is a boolean value to check whether a user is logged in on the system or not. I will be listing all users however the signed in user must be the first one in the list (example: when 'bob' is signed in, he will be the first in the list - on the other side on another server if 'mike' is signed in, he will be first in the list). – christianilvi Jun 08 '19 at 07:03
  • Solution found: https://stackoverflow.com/questions/5417980/mysql-sql-specific-item-to-be-first-and-then-to-sort-the-rest-of-the-items – christianilvi Jun 08 '19 at 07:30

1 Answers1

1

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.

flwd
  • 548
  • 3
  • 12