简体   繁体   English

和之后,mysql request()不起作用

[英]Mysql request () doesn't work after AND

when I have this request: 当我有此要求时:

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

It works 有用

But when I put the () it doesn't work: 但是当我放()时不起作用:

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

The point of putting the () is to put all the others OR together with the AND so the request shows only the result where all words typed are present in the text by searching for the ,. 放置()的目的是将所有其他OR与AND放置在一起,因此该请求仅显示搜索到的所有键入的单词都出现在文本中的结果。 and other characters 和其他字符

So ideally this should work: 因此理想情况下,这应该可以工作:

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

If that may helps I use this loop to get the amount of words: 如果那可以帮助我使用此循环获取单词数量:

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:]]?$'";
                }

        }
    }

It's in a function that is used as an argument in another fuction that part of it corresponds to the mysql request after WHERE. 它是在另一个函数中用作参数的函数,该函数的一部分与WHERE之后的mysql请求相对应。

Did you try to remove these seemingly superfluous '' after the last ) ? 您是否尝试过在最后一个)之后删除这些看似多余的文件?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM