how to link two records from different tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smileboy
Forum Newbie
Posts: 20
Joined: Wed Mar 11, 2009 6:58 am
Location: Tashkent, Uzbekistan

how to link two records from different tables

Post by smileboy »

hi, i was wondering if there is a way to display two records from different tables.

i have two tables in MySQL which are title and words

title contains id (auto increment) and title
words contains id, title, translation.


what i want is to display all titles from table 'title' as links.
when the link is followed, it leads to the page which displays all the records in table 'words' which the title is same

for example,

records in table 'title'
1. id=1, title=book
2. id=2, title=apple
3. id=3, title=car

records in table 'words'
1. id=1, title=book, translation=книга
2. id=2, title=book, translation=kitob
3. id=3, title=apple, translation=яблока
4. id=4, title=car, translation=машина

in the index page it should show all records in title and when they are followed it show the records in table words (title and translation)

cuz there may be several translations for one title, i've separated them into two tables

would be great if someone could help on dis
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: how to link two records from different tables

Post by JAB Creations »

Time for you to learn how to do a MySQL JOIN. Keep in mind that a LEFT JOIN will return any data even if some fields are null while an INNER JOIN won't return any data if any rows are null...I think.

Create a couple of tables to mimic the tutorial...once you learn how to do a JOIN in MySQL you'll now understand relational databases. You won't use a person's user-name associated with their forum post in example, just their ID. Then you join the post row's user-id with the user's id in the user's table...and BAM! You've got a forum post with the user's ID matching up both tables. That way if you allow the user to change their name you only have to do so once across the entire site even if they have a hundred thousand posts...all those posts will automatically pull the correct user name instead of manually changing their name statically assigned to every instance.
Post Reply