1

I am working on a user database for a Clan. I am really inexperienced with PHP and MySQL. The database selects users from a MySQL Table. The users have a nickname and a user_status.

The first version I wrote ordered the Users as followed:

$sql = $sql . " ORDER BY user_status, nickname ASC";

So now the clan Leaders wish that the active Members show up first on that list. The Problem with that is that there are user_status such as "abgelehnt" wich means user refused in German.

And thats where the Trouble starts. abgelehnt shows up higher than aktiv.

I am really thankful for any suggestions.

Paulie-C
  • 1,674
  • 1
  • 13
  • 29
Sebastian
  • 13
  • 6
  • Possible duplicate of [How to define a custom ORDER BY order in mySQL](http://stackoverflow.com/questions/9378613/how-to-define-a-custom-order-by-order-in-mysql) – Raunak Gupta May 08 '17 at 14:54

1 Answers1

1

You can try this one

$sql = " SELECT filed1, field2, field3 FROM tablename
ORDER BY FIELD(status, "active", "inactive", "canceled")";

Change name of priority values according yours

CyberAbhay
  • 494
  • 6
  • 17