Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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 如何从具有条件的两个表中进行选择_Php_Mysql - Fatal编程技术网

Php 如何从具有条件的两个表中进行选择

Php 如何从具有条件的两个表中进行选择,php,mysql,Php,Mysql,共有两个表格: 表1: id = 0 name=JOHN speciality =dentist id = 1 name=ABY speciality= dentist id = 2 name = SARA speciality= cardiologist ,… 表2: id = 0 name = JOHN city=paris id = 1 name

共有两个表格:

表1:

 id = 0      name=JOHN           speciality =dentist  
 id = 1      name=ABY            speciality= dentist  
 id = 2      name = SARA         speciality= cardiologist  
,…
表2:

 id = 0    name = JOHN           city=paris
 id = 1    name = ABY            city=tokio
 id = 1    name = SARA           city=london

 $city='pa';  

 $speciality='dentist';
(这两个变量来自用户输入的搜索表单)

我想说:

select * FROM Table 1 WHERE speciality=$speciality AND city LIKE %$city% (from Table2) ;
我该怎么说? (很明显,两个表的每一行的id都是相同的,每个id代表一个人)

尝试如下:

   select t1.* FROM Table 1 as t1,table2 as t2 WHERE t1.speciality='$speciality' AND t1.city  LIKE %$city%  and t1.name=t2.name;
如果两个表的行id相同,则:

   select t1.* FROM Table 1 as t1,table2 as t2 WHERE t1.speciality='$speciality' AND t1.city  LIKE %$city%  and t1.name=t2.name and t1.id=t2.id ;