久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP/MySQL 中的多詞搜索

Multi word search in PHP/MySQL(PHP/MySQL 中的多詞搜索)
本文介紹了PHP/MySQL 中的多詞搜索的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在努力創建一個搜索多個詞的搜索.我的第一次嘗試沒有任何結果,如下:

 require_once('database_conn.php');如果($_POST){$explodedSearch = 爆炸 (" ", $_POST['quickSearch']);foreach($explodedSearch 作為 $search){$query = "選擇 *來自求職者WHERE 前名如%$search%"或姓氏如%$search%"按用戶 ID 排序限制 5";$result = mysql_query($query);}while($userData=mysql_fetch_array($result)){$forename=$userData['forename'];$surname=$userData['surname'];$profPic=$userData['profilePicture'];$location=$userData['location'];echo "

<img 類="quickImage" src="" .$profPic."" 寬度="45" 高度="45"/><p class="quickName">" . $forename . " " . $surname . "</p><p class="quickLocation">" . $location . "</p>

";}}

我也嘗試了以下方法,結果得到了結果,但正如您想象的那樣,我輸入的每個單詞都得到了重復的結果:

if($_POST){$explodedSearch = 爆炸 (" ", $_POST['quickSearch']);foreach($explodedSearch 作為 $search){$query = "選擇 *來自求職者WHERE 前名如%$search%"或姓氏如%$search%"按用戶 ID 排序限制 5";$result .= mysql_query($query);while($userData=mysql_fetch_array($result)){$forename=$userData['forename'];$surname=$userData['surname'];$profPic=$userData['profilePicture'];$location=$userData['location'];echo "

<img 類="quickImage" src="" .$profPic."" 寬度="45" 高度="45"/><p class="quickName">" . $forename . " " . $surname . "</p><p class="quickLocation">" . $location . "</p>

";}}}

我非常不知道如何進行此操作,任何幫助將不勝感激.

if($_POST){$quickSearch = $_POST['quickSearch'];$explodedSearch = 爆炸(",修剪($quickSearch));$queryArray = array();foreach($explodedSearch 作為 $search){$term = mysql_real_escape_string($search);$queryArray[] = "forename like '%" .$term ."%' 姓氏如 '%" .$term ."%'";}$implodedSearch = implode(' or ', $queryArray);$query="選擇 *來自求職者WHERE ($implodedSearch)按用戶 ID 排序限制 5";$result = mysql_query($query);while($userData=mysql_fetch_array($result, MYSQL_ASSOC)){$forename=$userData['forename'];$surname=$userData['surname'];$profPic=$userData['profilePicture'];$location=$userData['location'];echo "

<img 類="quickImage" src="" .$profPic."" 寬度="45" 高度="45"/><p class="quickName">" . $forename . " " . $surname . "</p><p class="quickLocation">" . $location . "</p>

";}}

解決方案

我一直在研究同一主題(用關鍵字搜索)一段時間,這是我是如何做到的:

$words = $_POST['keywords'];如果(空($words)){//重定向到其他地方!}$parts = expand(" ",trim($words));$子句=數組();foreach ($parts 作為 $part){//function_description 在我的情況下,用你表中你想要的任何東西替換它$clauses[]="function_description LIKE '%" .mysql_real_escape_string($part) ."%'";}$clause=implode(' OR ' ,$clauses);//選擇您的條件并添加 "AND ($clauses)" .$sql="選擇 *FROM 函數在哪里用戶名='{$用戶名}'AND ($子句) ";$results=mysql_query($sql,$connection);如果(!$結果){重定向(錯誤/error_db.html");}否則如果($結果){$rows = array();<?phpwhile($rows = mysql_fetch_array($results, MYSQL_ASSOC)){//回顯你想要的任何東西!}?>

-- 現在這是我嘗試使用 FULLTEXT 搜索運行它時的樣子:但是您應該將表類型設置為MyISAM"

 1/2(列)=>它不會返回任何東西!(使用自然語言"=布爾值")$sql="SELECT * FROM 函數哪里匹配(function_description)反對 ('{$words}' 自然語言模式)";$results=mysql_query($sql,$connection);如果(!$結果){重定向(錯誤/error_db.html");}否則如果($結果){$rows = array();while($rows = mysql_fetch_array($results, MYSQL_ASSOC)){//回聲}}?>

I'm struggling to create a search that searches for multiple words. My first attempt yielded no results whatsoever and is as follows:

  require_once('database_conn.php');
  if($_POST){
  $explodedSearch = explode (" ", $_POST['quickSearch']);


  foreach($explodedSearch as $search){
  $query = "SELECT * 
            FROM jobseeker 
            WHERE forename like '%$search%' or surname like '%$search%' 
            ORDER BY userID 
            LIMIT 5";
  $result = mysql_query($query);
}

while($userData=mysql_fetch_array($result)){
    $forename=$userData['forename'];
    $surname=$userData['surname'];
    $profPic=$userData['profilePicture'];
    $location=$userData['location'];

    echo "<div class="result">
    <img class="quickImage" src="" . $profPic. "" width="45" height="45"/>
    <p class="quickName">" . $forename . " " . $surname . "</p>
    <p class="quickLocation"> " . $location . "</p>
    </div>";

}
}  

I also tried the following, which yielded results, but as you can imagine, I was getting duplicate results for every word I entered:

if($_POST){
$explodedSearch = explode (" ", $_POST['quickSearch']);


foreach($explodedSearch as $search){
$query = "SELECT * 
          FROM jobseeker 
          WHERE forename like '%$search%' or surname like '%$search%' 
          ORDER BY userID 
          LIMIT 5";
$result .= mysql_query($query);


while($userData=mysql_fetch_array($result)){
    $forename=$userData['forename'];
    $surname=$userData['surname'];
    $profPic=$userData['profilePicture'];
    $location=$userData['location'];

    echo "<div class="result">
    <img class="quickImage" src="" . $profPic. "" width="45" height="45"/>
    <p class="quickName">" . $forename . " " . $surname . "</p>
    <p class="quickLocation"> " . $location . "</p>
    </div>";
}
}
}

I'm pretty much at a loss as to how to proceed with this, any help would be greatly appreciated.

EDIT:

if($_POST){
$quickSearch = $_POST['quickSearch'];
$explodedSearch = explode (" ", trim($quickSearch));


$queryArray = array();

foreach($explodedSearch as $search){
$term = mysql_real_escape_string($search);
$queryArray[] = "forename like '%" . $term .  "%' surname like '%" . $term . "%'";
}

$implodedSearch = implode(' or ', $queryArray);

$query="SELECT *
        FROM jobseeker
        WHERE ($implodedSearch)
        ORDER BY userID
        LIMIT 5";

$result = mysql_query($query);

while($userData=mysql_fetch_array($result, MYSQL_ASSOC)){
    $forename=$userData['forename'];
    $surname=$userData['surname'];
    $profPic=$userData['profilePicture'];
    $location=$userData['location'];


    echo "<div class="result">
    <img class="quickImage" src="" . $profPic. "" width="45" height="45"/>
    <p class="quickName">" . $forename . " " . $surname . "</p>
    <p class="quickLocation"> " . $location . "</p>
    </div>";

}
}

解決方案

I've been working on the same subject (search with keywords) for a while and this how i did it :

$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 !
}
?>

-- Now this is how it look when i tried to run it with FULLTEXT search : But you should set the table type as "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 
}
}
?>

這篇關于PHP/MySQL 中的多詞搜索的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 夜夜爽99久久国产综合精品女不卡 | 99精品欧美一区二区三区综合在线 | 亚洲一区久久 | 天堂影院av | 亚洲美乳中文字幕 | 91精品综合久久久久久五月天 | 亚洲欧美日韩久久 | 国产精品久久久久久久免费大片 | 成人三级网址 | 国产精品永久 | 久久精品一区二区视频 | 久操av在线 | 成人在线视频免费观看 | 成人午夜激情 | 青青草网 | 亚洲国产精品一区二区久久 | 国产精品欧美一区二区三区 | 欧美国产精品一区二区三区 | 亚洲精品在线视频 | 国产欧美日韩综合精品一区二区 | 午夜电影在线播放 | 久久99国产精一区二区三区 | 久久av资源网 | 手机av在线 | a毛片| 天天干天天操天天爽 | 欧美性视频在线播放 | 亚洲免费在线观看 | 中文字幕综合 | 精品综合 | 91视频一区二区 | 久久久精品久 | 一区二区三区播放 | 超碰97人人人人人蜜桃 | 欧美成视频 | 在线婷婷 | 亚洲一区不卡在线 | 成年人在线观看视频 | 色资源站| 伊人久久在线观看 | 视频一区中文字幕 |