doufan9290 2018-06-28 17:46
浏览 55
已采纳

PHP / HTML使用两个表并获取在html表中使用的名称

i have a little problem, right now i'm making a little ticket system.

I have a table where it displayes available tickets created related to that user.

Example: User Nick has 3 tickets and it gets displayed like that.

+-----------+------------+---------+
| Ticket ID | Created by | Comment |
+-----------+------------+---------+
|     2     |     4      |  Text   | <- Ticket 1
+-----------+------------+---------+
|     3     |     2      |  Text   | <- Ticket 2
+-----------+------------+---------+
|     5     |     3      |  Text   | <- Ticket 3
+-----------+------------+---------+

Right now, i have only the userid in the column 'created by' but i want the username to be displayed instead.

I have two database tables and all users are saved in table 1 and the tickets get saved in table 2, now I need a query to get the username of the userid 4,2,3 to display the username in the HTML table but i don't know how to do that.

My current query looks like this:

$pdo->query("BEGIN");
$t = ("SELECT * FROM ticket WHERE uid='$param'");
$pdo->query("COMMIT");

To explane the 'uid', with the uid i get the tickets related to that player.

//Edit

That is not exactly that what i'm searching for, maybe i explained it a little bit wrong.

This is my ticket table: Ticket Table

First row: Ticket ID Second row: The UID identifes the user the ticket got created for Third row: the ID of the user that created the ticket.

Now i have the user table: User Table

First row: Identifes the user Third row: Is the username of the user

Now i have a html table(That's just a small part of the table): HTML Table

First row: The userid of the user created that ticket Second row: The ticket ID

Right now it displays all the tickets created for UID 76561198073236987 and instead of displaying only the ID of the user created the ticket i want to display the username.

  • 写回答

2条回答 默认 最新

  • douque8861 2018-07-02 19:55
    关注

    I solved this on my own with following Query.

    SELECT ticket.*, users.benutzername FROM ticket INNER JOIN users ON ticket.created_by=users.id WHERE uid='$param'
    

    In this example i replaced all my results with a "*" to make this query shorter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用