Php mysql search in 2 columns in 2 tables

I have two tables in one database, one called Cottages and one called Hotels. In both tables they have the same named fields.

I have a search bar in which I want it to run in both fields in both tables. (two fields are called "Name" and "Location"

I still have

$sql = mysql_query("SELECT * FROM Cottages WHERE Name LIKE '%$term%' or Location LIKE '%$term%' LIMIT 0, 30");

But this is only looking for a table "Cottages", how can I make him look for both cottages and hotel tables?

+3
source share
2 answers

, type ( , ), .

normalization, WordPress, , , sabe.

+3

TiuTalk - , , , .

, LIKE '%foo%' . . , LIKE . , , .

, UNION ALL :

(SELECT * FROM Cottages WHERE Name LIKE '%$term%' or Location LIKE '%$term%' LIMIT 15)
UNION ALL
(SELECT * FROM Hotels WHERE Name LIKE '%$term%' or Location LIKE '%$term%' LIMIT 15)

, , . SELECT *, - , .

+1
source

Source: https://habr.com/ru/post/1745654/


All Articles