PHPMySQL中的多词搜索

PHPMySQL中的多词搜索,第1张

PHP / MySQL中的多词搜索

我已经在同一个主题(搜索关键字)上工作了一段时间,这是我的工作方式:

$words = $_POST['keywords'];if(empty($words)){    //redirect somewhere else!}$parts = explode(" ",trim($words));$clauses=array();foreach ($parts as $part){    //function_description in my case ,  replace it with whatever u want in ur table    $clauses[]="function_description LIKE '%" . mysql_real_escape_string($part) . "%'";}$clause=implode(' OR ' ,$clauses);//select your condition and add "AND ($clauses)" .$sql="SELECT *       FROM functions       WHERe      user_name='{$user_name}'      AND ($clause) ";$results=mysql_query($sql,$connection); if(!$results){    redirect("errors/error_db.html"); } else if($results){ $rows = array();<?php  while($rows = mysql_fetch_array($results, MYSQL_ASSOC)){   // echo whatever u want !}?>

-现在这就是我尝试使用FULLTEXT搜索运行它的样子:但是您应该将表类型设置为“ MyISAM”

<?php$words = mysql_real_escape_string($_POST['function_keywords']);if(empty($words)){    redirect("welcome.php?error=search_empty");}//if the columns(results)>1/2(columns) => it will return nothing!(use "NATURAL LANGUAGE"="BOOLEAN")$sql="SELECt * FROM functions     WHERe MATCH (function_description)     AGAINST ('{$words}' IN NATURAL LANGUAGE MODE)";$results=mysql_query($sql,$connection); if(!$results){    redirect("errors/error_db.html"); } else if($results){$rows = array();while($rows = mysql_fetch_array($results, MYSQL_ASSOC)){     // echo }}?>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5022419.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存