2014-02-21 39 views
0

我的查詢看起來像如何使用避免擴展值的MySql Query來搜索確切的字符串?

$search_query = db_query("SELECT nd.nid, users.name, nd.type FROM node as nd 
LEFT JOIN node_revisions as nd_rev ON nd_rev.nid = nd.nid AND nd_rev.vid = nd.vid 
LEFT JOIN users ON nd.uid = users.uid 
WHERE nd.status = 1 AND nd_rev.body LIKE LOWER('%node/100%') 
AND nd.nid NOT IN(SELECT DISTINCT nid FROM term_node WHERE tid = 293)"); 

該查詢實際上是從node_revisions.body領域,其中包括 節點/ 1000節點/ 1001 ....等等,

我想返回所有的比賽得到的只是儘可能地像

"node/100" 
"node/100/" 
"/node/100" 
"/node/100/" 
'node/100' 
'node/100/' 
'/node/100' 
'/node/100/' 

和不喜歡精確匹配的結果

"node/1006" 
"node/10064/" 
"/node/1000" 
"/node/10001/" 
'node/10023' 
'node/1005/' 
'/node/1001' 
'/node/10069/' 

這上面的查詢返回的結果我擁有串像下面.. ..A HREF =「/節點/ 1006」

如何避免這種錯誤呢?請幫助..

回答

0

唉呀......我得到了一個解決方案..我重新定義了我的查詢,就像下面這樣,它gi VES我得到預期..

$search_query = db_query("SELECT nd.nid, users.name, nd.type FROM node as nd 
LEFT JOIN node_revisions as nd_rev ON nd_rev.nid = nd.nid AND nd_rev.vid = nd.vid 
LEFT JOIN users ON nd.uid = users.uid 
WHERE nd.status = 1 AND nd_rev.body RLIKE '[[:<:]]" . $search_string . "[[:>:]]' 
AND nd.nid NOT IN(SELECT DISTINCT nid FROM term_node WHERE tid = 293)"); 

nd_rev.body RLIKE '[[:<:]]" . $search_string . "[[:>:]]' 

這是我所期待的

1

嘗試取出後% 100因此搜索將不考慮任何位100後,像這樣:

LOWER('%node/100') 
相關問題