单击链接时显示另一个表上的displayname而不是另一个表中的外键PHP MYSQL [duplicate]
Possible Duplicate:
Displaying * in a table
i have 2 tables, users & tv shows. My users table holds user_id, username, displayname, password and my tv shows table holds, tv_id, user_id FK, showname and seasons.
My main index page displays all the results from the tvshows table and you can click on each individual result and it will take you to another page.
On my tvshows.php at the top of the page i want to display the name of the person who is assigned to that result in the tvshows table.
On my index.php:
Thank you!
This only displays the id of the person who created but i would like it to display the displayname. If i change user_id to displayname it won't work because its on a different table
You need to select from both tables using a JOIN. Just a quick example:
SELECT tvshows.user_id, users.displayname FROM tvshows, users WHERE (tvshows.user_id = users.user_id) AND (tvshow_id = '$tvshow_id')
JOIN
the two tables like so:
SELECT
u.displayname
FROM users u
INNER JOIN TVShows t ON u.user_id = t.user_id
WHERE t.tvshow_id = '$tvshow_id'