Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysql中构建三个表的查询_Php_Mysql - Fatal编程技术网

Php 在mysql中构建三个表的查询

Php 在mysql中构建三个表的查询,php,mysql,Php,Mysql,在搜索过程中,我需要从三个表中收集数据: 佣金表-表1:[附属机构id] 附属公司表-表2:[id][user\U id] 配置文件表-表3:[ID][昵称] 我的搜索输入是某人搜索用户名。我需要返回表1中的数据,其中关联方id与表2的用户id匹配,这就像将要搜索的昵称一样 我希望这是有意义的:试试这个: "select table1.* from table1 inner join table2 on table2.user_id = table1.affiliate_id inner j

在搜索过程中,我需要从三个表中收集数据:

佣金表-表1:[附属机构id] 附属公司表-表2:[id][user\U id] 配置文件表-表3:[ID][昵称]

我的搜索输入是某人搜索用户名。我需要返回表1中的数据,其中关联方id与表2的用户id匹配,这就像将要搜索的昵称一样

我希望这是有意义的:

试试这个:

"select table1.* from table1 inner join table2 on table2.user_id = table1.affiliate_id inner join table3 on table3.id = table2.user_id where table3.nickname like '%".mysql_real_escape_string($searchtext)."%'" 试试这个:

"select table1.* from table1 inner join table2 on table2.user_id = table1.affiliate_id inner join table3 on table3.id = table2.user_id where table3.nickname like '%".mysql_real_escape_string($searchtext)."%'"
我不确定我是否在这里加入了正确的字段,但是您的查询应该是这样的。哇,非常感谢。这非常有效。你能解释一下内部连接的作用吗?我想了解一下这个问题我不太擅长解释,这篇维基百科文章有它的全部:……我不确定我是否在这里加入了正确的字段,但是你的查询应该是这样的。哇,非常感谢。这非常有效。你能解释一下内部连接的作用吗?我想了解一下这个问题,我不太擅长解释,这篇维基百科文章有它的全部:。。