gpt4 book ai didi

php - mysql从多个文本框php中搜索多个单词

转载 作者:行者123 更新时间:2023-11-30 21:45:51 24 4
gpt4 key购买 nike

<分区>

我有一个包含三个文本框的表单,用户填写它并点击搜索按钮,它将重定向到另一个页面并显示结果。一切都很好。但问题是当用户在同一个文本框中输入两个词时

(例如:铁路殖民地)

它不会显示细节..为此我使用expolde方法插入“+”符号进行多词搜索

这是代码

 <?php  
if(isset($_GET["search"]))
{
$condition = '';
$query = explode(" ", $_GET["search"]);
foreach($query as $text)
{
$condition .= "address LIKE '%".mysqli_real_escape_string($connect, $text)."%' OR " ;
}
$condition = substr($condition, 0, -4);
$sql_query = "SELECT * FROM jposts WHERE " . $condition;

$result = mysqli_query($connect, $sql_query);

if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo '<tr><td>'.$row["address"].'</td></tr>';
}
}
else
{
echo '<label>Data not Found</label>';
}
}
?>

它适用于具有多词搜索的一个文本框..但是所有三个文本框呢

我之前的搜索查询是

$stmt = $search->runQuery("SELECT * FROM jposts WHERE city LIKE '%".$city."%' 
AND address LIKE '%".$location."%' AND business_name LIKE
'%".$category."%'");

我想为我所有的三个文本框实现多词搜索

for ex: In textbox1 user enters  : tirupati (city)
In textbox2 user enters : railway colony (location)
In textbox3 user enters : Lic agent (catagory)

点击搜索后我想根据以上数据显示相关信息

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com