-
new to table joins?
I have an activity table which has A_ID (PK), C_NUMBER (FK), A_DATE, A_DESC, and a MEDIVAS field. When I perform a search by date, all the dates in that column show up in a combo box, when a cerrtain date is selected, I'm trying to output all the info for that activity (description, medivas) as well as the coresponding company information (C_NUMBER) would be its unique identifier.
how do I do this using table joins?
thanks
-
Select *
From CompanyTable As C
Inner Join ActivityTable AS A On A.C_NUMBER = C.C_NUMBER
Where C.A_DATE = 'Date Value'
-
k
Thank you rawhide,
I did this
Select *
From COMPANY As C
Inner Join ACTIVITY AS A On A.C_NUMBER = C.C_ID
Where C.A_DATE = '$date'
COMPANY is the name of my company table
ACTIVITY is the name of my activity table
C_ID is the primary key of my company table
$date is the phhp variable of the date choosen.
How should I display the results, like this?
while ($result = mysql_fetch_array($query)){
print "<TD>".$result['C_NAME']."</TD>";
print "<TD>".$result['C_CITY'].", ".$result['C_STATE']."</TD>";
print "<TD>".$result['C_DESC']."</TD>";
print "<TD>".$result['RATIONALE']."</TD>";
print "<td>".$result['contact_NAME']."</TD>";
print "<td>".$result['contact_PHONE']."</td>";
print "<TD>".$result['A_DATE']."</TD>";
print "<TD>".$result['A_DESC']."</TD>";
print "<td>".$result['NEXT']."</TD>";
print "<td>".$result['MEDIVAS']."</td>";
print "</TR>\n";
}
How would I differentiate between the 2 tables if thats the case?
-
If there are no fields by the same name in the two tables, so all you need to know are the field names. If there are any by the same name, you'll need to alias one of the tables with a different name.