gpt4 book ai didi

php - mysql 查询 3 个表 php 输出名称而不是 id

转载 作者:行者123 更新时间:2023-11-28 23:29:12 25 4
gpt4 key购买 nike

需要一些帮助。我有 3 张 table 。客户,klientwithservice,服务。

table klients
id | klientrnd
---------
1 | 11231231
2 | 22222222

table service
id | servicename
---------
1 | Repair laptop
2 | Repair pc

table klientwithservice
id | klientrnd | serviceid
-------------------------------
1 | 11231231 | 1
2 | 11231231 | 2
3 | 22222222 | 1
4 | 22222222 | 2

我需要输出 SERVICENAME 而不是 ID。我的 sql 查询是:

SELECT serviceid FROM klientwithservice WHERE '$pole8' = `klientrnd`

$pole8 = klientrnd 正是我放置在哪个页面上的人。

最佳答案

为此你需要连接两个表

使用下面的查询

SELECT s.servicename FROM klientwithservice as kws
JOIN service as s ON s.id = kws.serviceid
WHERE `klientrnd` = '$pole8'

关于php - mysql 查询 3 个表 php 输出名称而不是 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com