Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:29:11+00:00 2026-05-14T06:29:11+00:00

I have 3 tables I need to join. The contracts table is the main

  • 0

I have 3 tables I need to join. The contracts table is the main table, the ‘jobs’ and ‘companies’ table are extra info that can be associated to the contracts table.

so, since I want all entries from my ‘contracts’ table, and the ‘jobs’ and ‘companies’ data only if it exists, I wrote the query like this….

$sql = "SELECT * FROM contracts
        LEFT JOIN jobs ON contracts.job_id = jobs.id
        LEFT JOIN companies ON contracts.company_id = companies.id
        ORDER BY contracts.end_date";

Now how would I output this in PHP? I tried this but kept getting an undefined error “Notice: Undefined index: contracts.id”…

$sql_result = mysql_query($sql,$connection) or die ("Fail.");

if(mysql_num_rows($sql_result) > 0){

    while($row = mysql_fetch_array($sql_result))
    {
       $contract_id = stripslashes($row['contracts.id']);
       $job_number = stripslashes($row['jobs.job_number']);
       $company_name = stripslashes($row['companies.name']);
    ?>
        <tr id="<?=$contract_id?>">
           <td><?=$job_number?></td>
           <td><?=$company_name?></td>
        </tr>
    <?  
    }
}else{
    echo "No records found";
}

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:29:11+00:00Added an answer on May 14, 2026 at 6:29 am

    The column names will not be prefixed like this – and with each table having a column called “id” you could be in trouble. You should explicitly identify the columns you want returned rather than using “select *”, and you then just retrieve the column by name un prefixed (e.g. $row['job_number']).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I need to join. These are: art id |
I have 3 tables that I need to join, these join together fine using
I have two tables which I need to join. First Table: EFF_DATE RATE CURRENCY
I have 2 tables with lots of data that I need to join. The
I have a table with more than 100 columns. I need to join it
I have two identical tables and need to copy rows from table to another.
I have 2 tables in a DB with very similar schemas that need to
I have tables contracts and users and i need to show contracts sorted by
I have 2 tables I need to join but the user_id column value is
I have 2 tables that I need to get information from, and would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.