To JOIN or not to JOIN that is the question
Posted: Thu Jan 24, 2008 11:25 pm
I have been reading for hours but I am at a stand still now. Help me learn how to accomplish this:
I have a php page that uses a variable passed by url to display information from a table. I have been using a very simple code for that:
I can display the correct data from the table but what I want to do is also display data from a secondary table that corresponds to one of the fields in the first table. Here are the fields that we are concerned with:
Table 1 lineitm:
SO_NO
SHIP_ID
other fields
Table 2 custshp:
SHIP_ID
other fields
I have tried to use JOIN and I can list table 1 and the corresponding ship_id in table 2 but it doesn't limit table one to so_no. Here is the code I am trying to edit to limit table 1 to so_no:
can I put a WHERE SO_NO=$id statement in here somewhere without getting an SQL error?
Thanks for the advice.
I have a php page that uses a variable passed by url to display information from a table. I have been using a very simple code for that:
Code: Select all
$id=$_GET['id'];
$query="SELECT * FROM lineitm WHERE SO_NO=$id";Table 1 lineitm:
SO_NO
SHIP_ID
other fields
Table 2 custshp:
SHIP_ID
other fields
I have tried to use JOIN and I can list table 1 and the corresponding ship_id in table 2 but it doesn't limit table one to so_no. Here is the code I am trying to edit to limit table 1 to so_no:
Code: Select all
$query = "SELECT lineitm.QTY,lineitm.DESCRIP, custshp.CITY ".
"FROM lineitm LEFT JOIN custshp ".
"ON lineitm.SHIP_ID = custshp.SHIP_ID";Thanks for the advice.