gpt4 book ai didi

php - 使用 UNION 查询 3 个表仅适用于其中 2 个表

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

好吧,我故意将三个用户表分开。我编写了一些 PHP 来允许任何用户(设计者/开发者/雇主)使用 UNION 查询登录,但这仅适用于开发者和雇主表。一旦我将 Designer 表添加到查询中,就无法登录。如果我在查询中仅使用 Designer 表,那也可以。有什么想法吗?

这曾经有效,但现在不行了(开发人员、雇主设计师

$email = clean_string($db_server, $email); 
$password = clean_string($db_server, $password);
$query = "SELECT * FROM connectdDB.developers WHERE developers.email='$email' UNION SELECT * FROM connectdDB.employers WHERE employers.email='$email' UNION SELECT * FROM connectdDB.designers WHERE designers.email='$email'";
$result = mysqli_query($db_server, $query);

这有效(开发商和雇主)

$email = clean_string($db_server, $email); 
$password = clean_string($db_server, $password);
$query = "SELECT * FROM connectdDB.developers WHERE developers.email='$email' UNION SELECT * FROM connectdDB.employers WHERE employers.email='$email'";
$result = mysqli_query($db_server, $query);

这有效(仅限设计师)

$email = clean_string($db_server, $email); 
$password = clean_string($db_server, $password);
$query = "SELECT * FROM connectdDB.designers WHERE designers.email='$email'";
$result = mysqli_query($db_server, $query);

设计师

id  | firstname | lastname | email | password | jobtitle | age | experience | bio | speciality
--------------------------------------- ------------------------------------------------------

开发人员

id  | firstname | lastname | email | password | jobtitle | age | experience | bio | 
--------------------------------------- -------------------------------------------

雇主

id  | firstname | lastname | email | password | businessname | businesstype | businesswebsite | businessbio |
-------------------------------------------------------------------------------------------------------------

最佳答案

Designers 有 10 列,其他有 9 列。Union 需要相同数量的列,您可以指定列

SELECT col1,col2... FROM t1 UNION SELECT col1,col2... FROM t2

使用别名来统一列名称。

关于php - 使用 UNION 查询 3 个表仅适用于其中 2 个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20476483/

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