久久久久久久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 | 婷婷在线网站 | 免费黄色网址视频 | 天天操夜夜操 | 狠狠综合网 | 久久久精品一区二区三区四季av | 欧美日韩成人网 | 人人澡人人爱 | 五月精品视频 | 国产91网站在线观看 | 欧美一区二区三区一在线观看 | www.久久.com | 久久久精品一区 | 免费久久99精品国产婷婷六月 | 在线国产一区二区 | 91久久久久| 中国一级特黄真人毛片免费观看 | 欧美一区二区三区小说 | 国产一区二区三区在线视频 | 中文字幕一区二区三区精彩视频 | 中文字幕免费在线 | 乱码av午夜噜噜噜噜动漫 | 激情a| 精国产品一区二区三区四季综 | 看一级毛片 | 蜜桃一区二区三区在线 | 伊人久久成人 | 国产精品亚洲综合 | 成人欧美一区二区三区在线播放 | 欧美激情啪啪 | 91精品麻豆日日躁夜夜躁 | 久久久久久久97 | 伊人网99| 91九色在线观看 | 中文字幕亚洲一区 | 日韩精品在线观看一区二区 | 久久久亚洲 |