Php 搜索包含多个单词的不同表
我有一张表格Php 搜索包含多个单词的不同表,php,search,mysqli,Php,Search,Mysqli,我有一张表格 <form action="buscar.php" method="GET"> <input type="text" name="q" /> </form> 当我查找绿色时,会显示两个结果,但如果我查找绿色房子则不会显示任何结果 问题是我必须搜索连续文本才能工作例如我的房子很小… 如何改进此查询?谢谢尝试分解获取变量。也可以尝试玩CONCAT 爆炸 $q = $_GET['q']; $word_array = explode(" ",$q)
<form action="buscar.php" method="GET">
<input type="text" name="q" />
</form>
当我查找绿色
时,会显示两个结果,但如果我查找绿色房子
则不会显示任何结果
问题是我必须搜索连续文本才能工作例如<代码>我的房子很小…
如何改进此查询?谢谢尝试分解
获取变量。也可以尝试玩CONCAT
爆炸
$q = $_GET['q'];
$word_array = explode(" ",$q);
$sqlnames="SELECT * FROM product_description WHERE";
$count = 0;
foreach($word_array as $value){
if($count == 0){
$sqlnames .= " description LIKE '" . $value ."'";
}
else{
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$count = 1;
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$sqlnames .="LIMIT 20";
CONCAT
(差不多)
我还没有测试过这个,但是你可以试着玩。试着分解获取
变量。或者你可以试着玩CONCAT
爆炸
$q = $_GET['q'];
$word_array = explode(" ",$q);
$sqlnames="SELECT * FROM product_description WHERE";
$count = 0;
foreach($word_array as $value){
if($count == 0){
$sqlnames .= " description LIKE '" . $value ."'";
}
else{
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$count = 1;
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$sqlnames .="LIMIT 20";
CONCAT
(差不多)
我还没有测试过这个,但是你可以试着玩
$q = $_GET['q'];
$word_array = explode(" ",$q);
$sqlnames="SELECT * FROM product_description WHERE";
$count = 0;
foreach($word_array as $value){
if($count == 0){
$sqlnames .= " description LIKE '" . $value ."'";
}
else{
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$count = 1;
$sqlnames .= " OR description LIKE '" . $value ."'";
}
$sqlnames .="LIMIT 20";
$results = DB::query("SELECT * FROM product_description WHERE description LIKE '%$q%' OR description LIKE '%$q%' OR CONCAT(description, ' ', description ) LIKE '%$q%' LIMIT 20");