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

PHP SQL SELECT where like search item with multiple words

PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
本文介紹了PHP SQL SELECT where like search item with multiple words的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個查詢表單的 select where like 查詢,如下所示:

I have a select where like query for a seach form which is as follows:

<?php 
$bucketsearch = sanitizeone($_POST["bucketsearch"], "plain");
$bucketsearch = strip_word_html($bucketsearch);
?>

 if(isset($_POST['search'])){
                  $result=MYSQL_QUERY( "SELECT * FROM buckets where bucketname like '%$bucketsearch%' order by bucketname");
              }else{
              $result=MYSQL_QUERY( "SELECT * FROM buckets order by bucketname");
          }

我的問題是,如果有人搜索例如apple and pear",我沒有得到任何包含任何單詞的結(jié)果,我只能讓它返回包含所有單詞的結(jié)果(1 個結(jié)果).

My problem is that if someone searches for instance for "apple and pear" i do not get any results that contain any of the words, i can only make it return results (well 1 result) with all the words in it.

誰能幫我讓這個搜索更通用一些??提前致謝.

Can anyone help me make this search a bit more versitle?? Thanks in advance.

推薦答案

所以您想要使用輸入的每個詞進(jìn)行 AND 搜索,而不是使用確切的字符串?這樣的事情怎么樣:

So you want an AND search using each of the words entered, rather than the exact string? Howabout something like this:

$searchTerms = explode(' ', $bucketsearch);
$searchTermBits = array();
foreach ($searchTerms as $term) {
    $term = trim($term);
    if (!empty($term)) {
        $searchTermBits[] = "bucketname LIKE '%$term%'";
    }
}

...

$result = mysql_query("SELECT * FROM buckets WHERE ".implode(' AND ', $searchTermBits).");

這會給你一個查詢:

SELECT * FROM buckets WHERE bucketname LIKE '%apple%' AND bucketname LIKE '%and%' AND bucketname LIKE '%pear%'

如果您想匹配任何搜索詞而不是全部,請將 AND 更改為 OR.進(jìn)一步的改進(jìn)可能涉及定義一些停用詞,例如和",以提供更好的結(jié)果.

change the AND to an OR if you want to match any of the search terms rather than all. Further improvements could involve defining some stop words like 'and' to give better results.

這篇關(guān)于PHP SQL SELECT where like search item with multiple words的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
PDO get data from database(PDO 從數(shù)據(jù)庫中獲取數(shù)據(jù))
主站蜘蛛池模板: 搞av.com | 亚洲 中文 欧美 日韩 在线观看 | 日韩一区二区在线视频 | 午夜爱爱毛片xxxx视频免费看 | 久久久久久国产精品久久 | 国外激情av | 理伦毛片 | 欧美性大战xxxxx久久久 | 97免费在线观看视频 | 午夜在线观看免费 | 精品久久中文 | 亚洲精品一二三 | 国产三级一区二区 | 国产精品视频久久久 | 国产成人久久精品一区二区三区 | www.日本在线播放 | 一区二区三区四区在线视频 | 国产剧情一区二区三区 | 精品国产一区二区三区免费 | 亚洲欧美一区二区三区1000 | 五月天激情综合网 | 欧美精品成人一区二区三区四区 | 亚洲精品99999 | 日韩一级免费大片 | 毛片黄片免费看 | a在线观看| 国产激情在线观看 | 81精品国产乱码久久久久久 | 91久久精品一区二区三区 | 在线观看亚 | 亚洲精品在 | 337p日本欧洲亚洲大胆鲁鲁 | 国产精品一区二区久久 | www..99re| 国产免费一区二区三区 | 福利一区二区在线 | 久久久妇女国产精品影视 | 国产成年人视频 | 天天夜夜操| 欧美高清一区 | 一本一道久久a久久精品综合 |