Skip to content
Advertisement

How do I get data from another table in MySQL?

I’m currently trying to link some databases up for a project I’m working on for my business. Here’s my below SQL I’m using for my PHP website.

JavaScript

At the moment my output goes like this to show what’s in each row using e.g. $lname=$lname["variable"]

JavaScript

I have another “clients” table, where each agency has an id – one that matches with $agency at this point. What I want to do is post the corresponding companyname column to that id.

How would I modify my code to do so (and access the column/rows from the secondary table)?

Advertisement

Answer

If I’ve understood the question correctly, the answer should look something like

JavaScript

The crux of it is the SQL JOIN clause.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement