,當我有這樣的要求:Mysql的請求()後不工作,
SELECT fr,text_id FROM texts
WHERE (
fr REGEXP '[>.:, ]le[<.:, ]' OR fr REGEXP '^le[[:space:]]?'
OR fr REGEXP '[[:space:]]le[[:space:]]?$'
) AND fr REGEXP '[>.:, ]la[<.:, ]' ''
ORDER BY text_id DESC LIMIT 0, 20
它的工作原理
但是,當我把()它不工作:
SELECT fr,text_id FROM texts
WHERE (
fr REGEXP '[>.:, ]le[<.:, ]' OR fr REGEXP '^le[[:space:]]?'
OR fr REGEXP '[[:space:]]le[[:space:]]?$'
) AND (fr REGEXP '[>.:, ]la[<.:, ]') ''
ORDER BY text_id DESC LIMIT 0, 20
把()放在所有其他位置或與AND一起,所以請求只顯示搜索到的所有文字類型出現在文本中的結果。和其他字符
所以最好這應該工作:
SELECT fr,text_id FROM texts
WHERE (
fr REGEXP '[>.:, ]le[<.:, ]'
OR fr REGEXP '^le[[:space:]]?'
OR fr REGEXP '[[:space:]]le[[:space:]]?$'
) AND (
fr REGEXP '[>.:, ]la[<.:, ]'
OR fr REGEXP '^la[[:space:]]?'
) OR fr REGEXP '[[:space:]]la[[:space:]]?$'
) '' ORDER BY text_id DESC LIMIT 0, 20
如果可能幫助我用這個循環將文字量:
for($i=0;$i<$wordsLenght;$i++)
{
if($i !== 0)
{
$recherche .= ")AND (".$lang." REGEXP '[>.:, ]".$words[$i]."[<.:, ]') ";
}
else
{
if($wordsLenght == 1)
{
$recherche = "".$lang." REGEXP '[>.:, ]".$words[0]."[<.:, ]' OR (".$lang."
REGEXP '^".$words[0]."[[:space:]]?') OR ".$lang." REGEXP
'[[:space:]]".$words[0]."[[:space:]]?$'";
}
else
{
$recherche = "(".$lang." REGEXP '[>.:, ]".$words[0]."[<.:, ]' OR ".$lang."
REGEXP '^".$words[0]."[[:space:]]?' OR ".$lang." REGEXP
'[[:space:]]".$words[0]."[[:space:]]?$'";
}
}
}
這是在用作功能在另一個函數中的一個參數,它的一部分對應WHERE之後的mysql請求。
你希望用這些空的''''做什麼? – Wrikken 2014-10-29 16:08:39
嘗試SELECT fr,text_id FROM texts WHERE(fr REGEXP'[>。:,] le [<。:,''或fr REGEXP'^ le [[:space:]]?'或fr REGEXP'[[:space :]] le [[:space:]]?$''AND(fr REGEXP'[>。:,] la [<。:,]')''ORDER BY text_id DESC LIMIT 0,20 – Abhijeet 2014-10-29 16:09:03
does not work ... – user3595784 2014-10-29 16:17:30