سؤال

I am trying to display the group members and group leader from phpbb3 on an external page. I can successfully display all the members, but instead I want the group leader on top just like the phpbb3 group list shows or the user name in bold, preferably the first one.

Here's what I have at the moment:

$sql = "SELECT phpbb_users.user_id, phpbb_user_group.group_id, phpbb_users.username, phpbb_profile_fields_data.pf_country, phpbb_profile_fields_data.pf_class  FROM phpbb_users, phpbb_profile_fields_data, phpbb_user_group WHERE phpbb_user_group.group_id IN(23) AND phpbb_users.user_id = phpbb_profile_fields_data.user_id AND phpbb_users.user_id = phpbb_user_group.user_id ORDER BY phpbb_users.username";

After that I am kind of unsure what do to do because If I include group leader in there it will only filter group leader and not the entire group.

هل كانت مفيدة؟

المحلول

Use this query:

$sql = "SELECT phpbb_users.user_id, phpbb_user_group.group_id, phpbb_users.username, phpbb_profile_fields_data.pf_country, phpbb_profile_fields_data.pf_class, phpbb_user_group.group_leader FROM phpbb_users, phpbb_profile_fields_data, phpbb_user_group WHERE phpbb_user_group.group_id IN(23) AND phpbb_users.user_id = phpbb_profile_fields_data.user_id AND phpbb_users.user_id = phpbb_user_group.user_id ORDER BY group_leader, phpbb_users.username";

This will add one more column to the end of your list: phpbb_user_group.group_leader and order by that column and then username. If this column contains a 1, they are a group leader. If it contains a 0 they are just a regular group member.

Sample output:

+---------+----------+----------------+--------------+--------------+--------------+
| user_id | group_id | username       | pf_country   | pf_class     | group_leader |
+---------+----------+----------------+--------------+--------------+--------------+
|     123 |       23 | Person 3       |           US |           12 |            1 |
|     543 |       23 | Person 1       |           UK |           13 |            0 |
|     714 |       23 | Person 2       |           DE |           01 |            0 |
+---------+----------+----------------+--------------+--------------+--------------+
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top