Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Location
    Bristol
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'Linking' two mysql tables

    This is one of those questions that involves PHP and MySQL so I wasn't sure where to put it. Anyway....What I want to do if possible is effectively 'link' two bits of data from two separate tables together.

    So...my two tables are as follows:

    groups table:
    ID | Groupname
    1 | Admin
    2 | Editors
    3 | Users

    user table:
    ID | Group
    1 | 1
    2 | 3
    3 | 2

    So, I want to display a user's information from the user table and then match the group number up with the ID in the groups table and then display the groupname.

    e.g User ID 1 is in group 1, therefore his output would be something like:

    user id = 1
    group = Admin

    Hope its clear what I want to do

    thanks
    Alex
    Last edited by Alex!; 11-14-2006 at 10:50 AM.

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Nigeria
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i gues what u need is a sql statement that goes something like this
    Code:
    select gt.groupname from user_table ut, group_table gt where ut.group=gt.id
    by the way, u may av to rename the table field with the name 'group' to something like 'grp' coz it may cause u a lot of headaches later - 'group' is a mysql reserve word.

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Hi Alex

    for future reference, ask your database questions in the mysql forum. if you are having trouble getting the results of your database query to appear correctly using PHP (or whatever) then post the question in that forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •