how i can search multiple word search in Mysql Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmad641
    New Member
    • Nov 2015
    • 1

    how i can search multiple word search in Mysql Database

    ***> here is the code***.
    > when i search single word like GOOGLE then the result is appear
    > if i search two or more word search then the result is not appear.


    Code:
    <?php
        include("connection.php");
        @ob_start();
        session_start();
        $GLOBALS['q']=isset($_GET['q']) ? htmlspecialchars(urldecode(urlencode($_GET['q']))):"";
        $GLOBALS['displayQ']=$GLOBALS['q'];
        $GLOBALS['q']=strtolower($GLOBALS['q']);
        $GLOBALS['p']=isset($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p']:1;
        $GLOBALS['dbh']=$dbh;
    
        function htmlFilt($s){
         $s=str_replace("<", "&lt;", $s);
         $s=str_replace(">", "&gt;", $s);
         return $s;
        }
        function head($title="", $IncOtherCss=array()){
         $title=$title=="" ? "Search" : $title." - ";
         /* Display The <title> tag */
         echo "<title>$title</title>";
         /* The Stylesheets */
         $cssFiles = array_merge(
          array(
           "all",
           "http://fonts.googleapis.com/css?family=Poiret+One"
          ),
          $IncOtherCss
         );
         foreach($cssFiles as $css){
          $url=preg_match("/http/","/wwww/", $css) ? $css : HOST."/spills/$search.css";
          echo "<link href='".$url."' async='async' rel='stylesheet' />";
         }
         
    
         
    
    
        /* Results */
        function getResults(){
         $q=$GLOBALS['q'];
         $p=$GLOBALS['p'];
         $start=($p-1)*10;
         if($p!=null){
          $starttime = microtime(true);
          $sql=$GLOBALS['dbh']->prepare('SELECT title, url, description FROM search WHERE `title` LIKE :q OR `url` LIKE :q OR `description` LIKE :q ');
          $sql->bindValue(":q", "%$q%");
          $sql->execute();
          $trs=$sql->fetchAll(PDO::FETCH_ASSOC);
          $endtime = microtime(true);
          if($sql->rowCount()==0 || $start>$sql->rowCount()){
           return 0;
          }else{
           $duration = $endtime - $starttime;
           $res=array();
           $res['count']=$sql->rowCount();
           $res['time']=round($duration, 4);
           $limitedResults=array_slice($trs, $start, 12);
           foreach($limitedResults as $r){
            $res["results"][]=array($r['title'], $r['url'], $r['description']);
           }
           return $res;
          }
         }
        }
        ?>
    Last edited by Rabbit; Nov 24 '15, 09:33 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • adriancs
    New Member
    • Apr 2011
    • 122

    #2
    Code:
    select * from member where name like '%word1%word2%word3%';

    Comment

    Working...