在users表中对一组用户进行排序


Sorting a group of users among themselves in users table

我有users表,我在该表中存储了所有用户(管理员、作者和普通用户)。我想把作者(在报纸上写专栏文章的人)排序。那么我应该走哪条路呢?我不知道该怎么办。虽然我尝试了一些方法。我添加了一个"订单"列到用户表,我不知道下一步该怎么做。请给我一些建议。我的表结构:

+----+-----------------+------------------+-------+-----------+-------+
| id | username        | password         | order | is_author | level |
+----+-----------------+------------------+-------+-----------+-------+
|  1 | admin2          | pass             |     0 |         0 |     3 |
|  2 | admin1          | pass             |     0 |         0 |     3 |
|  3 | writer&admin    | pass             |     0 |         1 |     3 |
|  4 | normaluser      | pass             |     0 |         0 |     0 |
|  5 | writer          | pass             |     0 |         1 |     1 |
+----+-----------------+------------------+-------+-----------+-------+

附加信息:

三级-超级管理员二级-编辑(只能添加新闻和管理用户)一级-作者级别0 -普通用户

为什么我需要is_author列?

因为不是每个编辑或超级管理员都是作家。对于作者和管理员,我添加了一个额外的列is_author.

给我一些建议

对于您的方法,创建2个表


1)用户2) user_role


users表:

 +----+-----------------+------------------+--------------+----------+
 | id | username        | password         | role_id (FK) | priority |
 +----+-----------------+------------------+--------------+----------+
 |  1 | admin2          | pass             |            1 | NULL     |
 |  2 | admin1          | pass             |            1 | NULL     |
 |  3 | writer&admin    | pass             |            2 | 1        |
 |  4 | normaluser      | pass             |            4 | NULL     |
 |  5 | writer          | pass             |            3 | 3        |
 +----+-----------------+------------------+--------------+----------+


user_role表:

 +----+---------------------------+--------+
 | id | role                      | level  |
 +----+---------------------------+--------+
 |  1 | admin                     | 1      |
 |  2 | writer and admin          | 2      |
 |  3 | writer                    | 3      |
 |  4 | user                      | 4      |
 +----+---------------------------+--------+