Getting Data From a Foreign Key
I have two tables:
I wanted to know how to create mysql_query that can get ArticleContent, CategoryName FROM tblArticle without accessing the tblcategory?
I appreciate any type of help....
The only way you can return CategoryName without accesing tblcategory is to move that field into tblArticle.
However this destroys the whole purpose of having seperated it into another table in the first place, and assuming that you have created two tables due to a one to many or many to many relationship will result in a lot of data duplication.
The query you need will access both tables at the same time:
SELECT A.ArticleContent, C.CategoryName
FROM tblArticle A, tblcategory C
WHERE A.CategoryID(FK) = C.CategoryID(FK);
When this is returned in PHP you reference the resultset with out the post fix i.e.
P.S. in the SQL you can replace the A and the C with anything you like as long as it is the same throughout the query.
Last edited by Brooksie155; 02-10-2006 at 04:47 AM.
yes & no
i think i understand but what do you mean by replacing A & C with anything...
can you give me an example
nvw i get it now...thanks
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)