By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,883 Members | 1,952 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,883 IT Pros & Developers. It's quick & easy.

how i can search multiple word search in Mysql Database

P: 1
***> 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.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include("connection.php");
  3.     @ob_start();
  4.     session_start();
  5.     $GLOBALS['q']=isset($_GET['q']) ? htmlspecialchars(urldecode(urlencode($_GET['q']))):"";
  6.     $GLOBALS['displayQ']=$GLOBALS['q'];
  7.     $GLOBALS['q']=strtolower($GLOBALS['q']);
  8.     $GLOBALS['p']=isset($_GET['p']) && is_numeric($_GET['p']) ? $_GET['p']:1;
  9.     $GLOBALS['dbh']=$dbh;
  10.  
  11.     function htmlFilt($s){
  12.      $s=str_replace("<", "&lt;", $s);
  13.      $s=str_replace(">", "&gt;", $s);
  14.      return $s;
  15.     }
  16.     function head($title="", $IncOtherCss=array()){
  17.      $title=$title=="" ? "Search" : $title." - ";
  18.      /* Display The <title> tag */
  19.      echo "<title>$title</title>";
  20.      /* The Stylesheets */
  21.      $cssFiles = array_merge(
  22.       array(
  23.        "all",
  24.        "http://fonts.googleapis.com/css?family=Poiret+One"
  25.       ),
  26.       $IncOtherCss
  27.      );
  28.      foreach($cssFiles as $css){
  29.       $url=preg_match("/http/","/wwww/", $css) ? $css : HOST."/spills/$search.css";
  30.       echo "<link href='".$url."' async='async' rel='stylesheet' />";
  31.      }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.     /* Results */
  38.     function getResults(){
  39.      $q=$GLOBALS['q'];
  40.      $p=$GLOBALS['p'];
  41.      $start=($p-1)*10;
  42.      if($p!=null){
  43.       $starttime = microtime(true);
  44.       $sql=$GLOBALS['dbh']->prepare('SELECT title, url, description FROM search WHERE `title` LIKE :q OR `url` LIKE :q OR `description` LIKE :q ');
  45.       $sql->bindValue(":q", "%$q%");
  46.       $sql->execute();
  47.       $trs=$sql->fetchAll(PDO::FETCH_ASSOC);
  48.       $endtime = microtime(true);
  49.       if($sql->rowCount()==0 || $start>$sql->rowCount()){
  50.        return 0;
  51.       }else{
  52.        $duration = $endtime - $starttime;
  53.        $res=array();
  54.        $res['count']=$sql->rowCount();
  55.        $res['time']=round($duration, 4);
  56.        $limitedResults=array_slice($trs, $start, 12);
  57.        foreach($limitedResults as $r){
  58.         $res["results"][]=array($r['title'], $r['url'], $r['description']);
  59.        }
  60.        return $res;
  61.       }
  62.      }
  63.     }
  64.     ?>
Nov 24 '15 #1
Share this Question
Share on Google+
1 Reply


100+
P: 122
Expand|Select|Wrap|Line Numbers
  1. select * from member where name like '%word1%word2%word3%';
Dec 23 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.