gpt4 book ai didi

php - Mysql 选择多个查询

转载 作者:行者123 更新时间:2023-11-29 08:27:26 26 4
gpt4 key购买 nike

我有这张表:

------------------------------
|ID | name | employee_code |
------------------------------
|24 | Robert | 20234 |
------------------------------

并且

-------------------------------------
|ID | job_code | team |
-------------------------------------
|24 | 241124 | Robert, Eduard, Etc. |
-------------------------------------

我想通过员工代码在第二个表中搜索,我尝试这样的操作:

$sql=mysql_query("SELECT * FROM works WHERE (SELECT name FROM employee WHERE employee_code LIKE '%".$_GET['employee_code']."%' AS searchname) team Like %searchname% ");

结果:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

最佳答案

尝试这个查询 -

$employee_code = mysql_real_escape_string($_GET['employee_code']);

$sql=mysql_query("SELECT w.*
FROM employee e
JOIN works w
ON w.team LIKE CONCAT('%', e.name ,'%')
WHERE employee_code LIKE '%$employee_code%'");

查看此 SQLFiddle 示例 - http://sqlfiddle.com/#!2/8f8b7/1

关于php - Mysql 选择多个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17542917/

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