0

Good morning!

Would like to perform a search with several words that will be passed on the html input.

Examples:

  • If you enter "gfilgueiras" will return 3 records.
  • If you enter "informativo gfilgueiras" will return 2 records.
  • If you enter "gfilgueiras :: 2" will return only 1 record.

I do a direct search for viewLogs.

I tried the concat, but did not succeed.

I'm sorry if my English is not good, I'm using a translator.

Sample Data:

Screenshot

Thank you all.

5
  • Please share the query you are using to search. May 6, 2014 at 4:55
  • What is the order you wish to search? Like <serverid>[login]<ip> ?
    – Hans
    May 6, 2014 at 4:56
  • SELECT * FROM viewLogs WHERE concat(ip,login, descricao, data, hora, acao, severidade) REGEXP "gfilgueiras" May 6, 2014 at 5:02
  • have you tried like '%gfilgueiras%' instead of REGEXP "gfilgueiras"?
    – Bryan P
    May 6, 2014 at 5:04
  • It's work, but i need more arguments in my query example: gfilgueiras erro May 6, 2014 at 5:08

2 Answers 2

0

What you want is not possible, you need to use AND on your WHERE clause, assuming the search word delimiter is space.

// $searchWord is informativo gfilgueiras
if(!empty($searchWord)) {

     // separates the searched word by space and puts it in array, if no space, put in array.
     $searchWords = strpos($searchWord,' ') !== false ? explode(' ',$searchWord) : array($searchWord);

     // this is just an example, use sql prepared statement for this
     $sqlString = "SELECT * FROM viewLogs WHERE concat(ip,login, descricao, data, hora, acao, severidade) REGEXP '$searchWord[0]' ";

     if(count($searchWords) > 0) {
         if(isset($searchWords[0])) {
             foreach($searchWords as $index => $searchWord) {
                 if($index > 0) {
                     // this is just an example, use sql prepared statement for this
                     $sqlString .= "AND WHERE concat(ip,login, descricao, data, hora, acao, severidade) REGEXP '$searchWord'";
                 }
             }
         }
    }
}
0
SELECT * FROM viewLogs WHERE concat(all field you want ) REGEXP "gfilgueiras"
1
  • It's work, but i need more arguments example: gfilgueiras erro May 6, 2014 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.