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
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display related value

    Wad Up, i'm brand new to mysql/php but have limped by using dreamweaver. I got an issue. I'm displaying personnel actions data in a details page based on the ID of the personnel action record, but would like to display a value (Employee Name) from a related table (tblemployees) based on a payroll_num field in the details page. These two fields are related, payroll_num and payrollID(primary in tblemployees). How do I add both tables in my query or is this the right way to get this accomplished?

    Need major help

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to use a JOIN. Do a Google on MySQL JOIN or something similar to get more in-depth tutorials, but the general idea for what it sounds like you want to do is:

    Code:
    SELECT
     t1.foo
    ,t2.bar
    FROM
     table1 AS t1 
    INNER JOIN
     table2 AS t2
    ON
     t1.relatedcolumn = t2.relatedcolumn
    WHERE
     t1.idcolumn = x
    That will only return rows where both tables have matching values in their related columns. If you need to return all rows of table1 whether they have a matching table2 value or not, use a LEFT JOIN instead of INNER. A good tutorial will have more info.

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks KC for the reply, I'll follow your advice. If anyone else has some insight, its appreciated. This is a great 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
    •