2013-01-22 30 views
0

我在mysql中使用多表select語句來過濾來自某些用戶輸入的查詢。輸入的$ _POST值是:1.zipcode [來自位置表]或2.city [來自位置表]和/或3.on_date [來自日曆表]和/或4.title [來自發布表]。MYSQL多表加入使用模式匹配/ JOIN

FROM table_many 
INNER JOIN posts ON posts.title LIKE '%{$title}%' 
INNER JOIN users ON users.user_id = posts.user_id 
INNER JOIN locations ON locations.post_id = posts.post_id AND locations.city = '$city[0]' 
LEFT JOIN calendar ON calendar.post_id = posts.post_id AND calendar.on_date = '$date' 
LEFT JOIN uploads ON posts.post_id = uploads.post_id 
WHERE table_many.cat_id = '$row_cat[0]' AND table_many.post_id = posts.post_id"; 

此安裝工程的位置。我可以輸入一個郵政編碼或一個城市,並且查詢可以正確過濾,但是根據輸入設置的$ date和$ title值不會檢索任何記錄。

任何想法?或者你需要更多信息?提前致謝。

+0

最有可能的日期格式是不同的:)你能證明你有什麼日期格式..或者您可以使用'date_format()'將日期格式化爲一種通用格式。 – bonCodigo

+0

'%{title}%'缺少'$'... –

+0

我在輸入中使用的日期格式與列格式相同 – user1753012

回答

0

您在標題冷落的tablename INNER JOIN posts ON title LIKE '%{$title}%'

嘗試 tableName.title

我沒有看到與查詢,這將使它無法工作任何東西,但還是讓我在它有一個再看看

+0

是啊,我的posts.title LIKE在我的代碼中。我想知道我是否可以在ON語句中使用? – user1753012