FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Call a value through Foreign id from another table(DW+PHP)





pashmina
Well here is the example layout of my database

table->contact
contactID - primary key
name
phoneNo
address
companyID - foreign key

table->company
companyID
companyName
companyContacts
companyAddress

I am working on this script with dreamweaver

with dreamweaver i created a recordset for the table contact
then made it to display its details

i want to display is the name and address of the company instead of the companyID
is this possible in any ways
wylieconlon
I think your question is confusing, and it would help if you could provide some more information to help others answer it.

First, I think your tables are correctly separated. Contact information and company information are unrelated, and therefore deserve separate tables. If you want to put them together, you could use the JOIN statement. You could also just get the information from the first table and use a second query to get the necessary information from the second.
rvec
SELECT contact.name, company.companyName FROM contact LEFT JOIN company ON contact.companyID=company.companyID;

That would get all the contactnames and the companyname which the contact is with.
pashmina
Code:
SELECT contact.name, company.companyName FROM contact LEFT JOIN company ON contact.companyID=company.companyID;

This worked perfectly..
thank you so much.. +karma..
but what if there is three table that needs to be joint.

also can you please see this post as well http://www.frihost.com/forums/vt-103944.html
rvec
Code:
SELECT contact.name, company.companyName FROM (contact LEFT JOIN company ON contact.companyID=company.companyID) LEFT JOIN project ON contact.ProjectID=Project.ID;


That would be 3 tables.
Code:

SELECT contact.name, company.companyName FROM ((contact
LEFT JOIN company ON contact.companyID=company.companyID)
LEFT JOIN project ON contact.projectID=project.ID)
LEFT JOIN other_table ON contact.other.ID=other_table.ID;


and so on..
pashmina
rvec wrote:
Code:
SELECT contact.name, company.companyName FROM (contact LEFT JOIN company ON contact.companyID=company.companyID) LEFT JOIN project ON contact.ProjectID=Project.ID;


That would be 3 tables.
Code:

SELECT contact.name, company.companyName FROM ((contact
LEFT JOIN company ON contact.companyID=company.companyID)
LEFT JOIN project ON contact.projectID=project.ID)
LEFT JOIN other_table ON contact.other.ID=other_table.ID;


and so on..

Thank you for the code.
i will surely need this in future.. i have stored it as a snippet.
Related topics
The Pros and Cons of Broadband Internet Phone
PHP VS ASP
Need Help Yet again :: Comment system, data from 3 tables !!
Need Help integrating php variable into mySQL SELECT query
mySQL Query/PHP code - get the highest value...
form destroys table-based design
Einstein proves Religion
Megaman Phoenix
How do I categorize content?
rows in a table
Relatively Secure Session Management System for PHP
AUTO INCREMENT VALUE
Tables
Recognizing Spam on FriHost
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.