Y
Y
Yevhenii K2015-12-01 13:51:47
PHP
Yevhenii K, 2015-12-01 13:51:47

How to search the site?

Good afternoon! Tell me, is it possible to make a search on the site without using add. modules (sphinxsearch etc)?
There is a database with news, when I search for a resource (1 word) it finds it, but the name has more and, accordingly, does not find anything if you do not use the full name.

public  function search ($querys) {  
      $querys = parent::obj()->connect()->quote($querys);
      $news = "SELECT * FROM `news` 
                            WHERE `title` LIKE $querys
                            OR `resource_name` LIKE $querys 
                            OR `content` LIKE $querys";
    $getnews = parent::obj()->connect()->query($news);
      
      if(is_null($getnews)) {
          return [];
        }
    
    return $getnews->fetchALL(PDO::FETCH_ASSOC);
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2015-12-01
@MaxDukov

and in general there is a more correct mechanism for this - full-text search. Mysql
LIKE searches without an index - you risk getting notable brakes.

D
Denis, 2015-12-01
@prototype_denis

To begin with, take a look at least one eye in the dock.
www.mysql.ru/docs/man/String_comparison_functions.html
...and then add percent signs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question