我需要在hostel
表中搜索。使用LIKE作爲2列
結構:
CREATE TABLE hostel(
p_id VARCHAR(5) NOT NULL,
hostel VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL
PRIMARY KEY(p_id));
我已經插入搜索詞$word
select * from hostel where hostel like '%$word%'
將在下面的查詢工作?我需要在這兩個 「宿舍」 和 「地址」 欄搜索
select * from hostel where hostel like '%$word%' AND address like '%$word%'
爲什麼不你只是測試它? – Sirko
這取決於你想要什麼。您的查詢只會導致旅館,其中旅館和地址的文字$字。我想你想要的是將AND更改爲OR,因此當宿舍或地址包含$ word時,它會返回行。 – Tom