>這裏是代碼。如何在Mysql數據庫中搜索多個詞搜索
i want to search the every word in my database but the results only show with single keyword not the multiple. it is a PDO database when i search single word like facebook then the result is appear if i search two or more word search then the result is not appear.
'
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;
}
}
}
?>
'
你如何傳遞多個單詞?在1變量? – davejal
你的意思是我添加另一個變量..? – Altamash
你想讓你的搜索搜索Facebook並在域中鏈接嗎?如果是的話,你想如何將它們傳遞給您的查詢 – davejal