Join MySQL tables
Posted: Thu Dec 23, 2004 7:58 am
I am having a problem with joining 2 tables, and getting the required output. I currently have a member list where people can choose how they want to see it; either sorted by usernames, userlevels, joined date etc.
I have done everything for it apart from the userlevels, which I need to join 2 tables. In the userlevel table I have the order in which to display the levels. For simplicity, the table could look a bit like below.
ID order userlevel
1 1 Admin
2 3 Member
3 2 Moderator
The member table could look a bit like below
ID username userlevel
1 Chris Admin
2 John Member
3 Olly Moderator
4 Matt Member
5 Dave Member
I need to get the order, and then display each user in terms of their userlevel, and then username, so the output would look like below:
Chris
Olly
Dave
John
Matt
I am using this code at the moment:
$perPage is simply how many users to display on one page.
Any help would be gratefully appreciated,
Thanks, Archy.[/google]
I have done everything for it apart from the userlevels, which I need to join 2 tables. In the userlevel table I have the order in which to display the levels. For simplicity, the table could look a bit like below.
ID order userlevel
1 1 Admin
2 3 Member
3 2 Moderator
The member table could look a bit like below
ID username userlevel
1 Chris Admin
2 John Member
3 Olly Moderator
4 Matt Member
5 Dave Member
I need to get the order, and then display each user in terms of their userlevel, and then username, so the output would look like below:
Chris
Olly
Dave
John
Matt
I am using this code at the moment:
Code: Select all
$sql = "SELECT * FROM `users`, `levels` ORDER BY levels.order, levels.userlevel LIMIT $perPage";Any help would be gratefully appreciated,
Thanks, Archy.[/google]