2015-05-13 37 views
-1

所以我的情況是這樣的。我有下面的查詢來獲取數據庫中的帖子,在LIKE內使用的字來自input textmonth來自select tag。所以當我鍵入Bresciainput box它提取brescia這是正確的結果,但是當我選擇monthbrescia它確實只返回與brescia職位,並不去月掃描。我有月份字段,如:man_date格式2015-04-12從表中選擇和月份()= 4

SELECT wp_posts.*,MONTH(wp_posts.man_date) as month 
FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
INNER JOIN wp_term_taxonomy 
ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) 
INNER JOIN wp_locations 
ON (wp_posts.ID = wp_locations.post_id) 
WHERE wp_term_taxonomy.taxonomy = 'tipo_manifestazione' 
AND wp_term_taxonomy.term_id = 97 AND wp_posts.post_type = 'manifestazione' AND MONTH(wp_posts.man_date) = 4 
AND wp_posts.post_status = 'publish' 
AND wp_posts.vip = 'NULL' 
AND wp_locations.continente LIKE '%Brescia%' 
OR wp_locations.nazione LIKE '%Brescia%' 
OR wp_locations.regione LIKE '%Brescia%' 
OR wp_locations.citta LIKE '%Brescia%' 
OR wp_locations.luogo LIKE '%Brescia%' 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.ID DESC 

回答

0

我覺得你人失蹤來自各地的或類似條款括號: -

SELECT wp_posts.*, MONTH(wp_posts.man_date) as month 
FROM wp_posts 
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) 
INNER JOIN wp_locations ON (wp_posts.ID = wp_locations.post_id) 
WHERE 
    wp_term_taxonomy.taxonomy = 'tipo_manifestazione' 
    AND 
    wp_term_taxonomy.term_id = 97 
    AND 
    wp_posts.post_type = 'manifestazione' 
    AND 
    MONTH(wp_posts.man_date) = 4 
    AND 
    wp_posts.post_status = 'publish' 
    AND 
    wp_posts.vip = 'NULL' 
    AND 
    ( 
     wp_locations.continente LIKE '%Brescia%' 
     OR 
     wp_locations.nazione LIKE '%Brescia%' 
     OR 
     wp_locations.regione LIKE '%Brescia%' 
     OR 
     wp_locations.citta LIKE '%Brescia%' 
     OR 
     wp_locations.luogo LIKE '%Brescia%' 
    ) 
    GROUP BY wp_posts.ID 
    ORDER BY wp_posts.ID DESC 
+0

我的查詢通過搜索返回帖子,但是使用上面的查詢返回0. –

1

的「%」符號是用來定義之前和模式之後的通配符(失蹤字母)。所以如果你想過濾「佈雷西亞」,不要使用通配符。

+0

實際上這只是一個示例詞,但實際上它是javascript的keyup函數,它將每個單個字符的更新發送到查詢。與阿賈克斯。 –