我如何在许多表中搜索?

I would like to do a search in many tables with a

<input type="text" name="search" />

$sql = mysql_query("SELECT * FROM cars,people,cities WHERE 
cars.reg= '$search' || people.phone = '$search' || city.address = '$search'");

Is it possible to do that? any suggestions for that a DB search with PHP?

Thanks a lot

You could use a UNION ALL query

SELECT name as findValue,
'cars' as tableName
FROM cars 
where cars.name = "$search"
UNION ALL
SELECT name as findValue,
'people' as tableName
FROM people
where people.name = "$search"
UNION ALL
SELECT city as findValue,
'cities' as tableName
FROM cities 
where cities .name = "$search"

It's important that you return the same type of field from all the subqueries. Read here for more info, basically the idea is that you return a UNION of all data found from the queries.