dpbl91234 2012-12-02 13:18
浏览 25
已采纳

单击链接时显示另一个表上的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

  • 写回答

2条回答 默认 最新

  • duankan8739 2012-12-02 13:26
    关注

    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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题