提问人:Nitin Prajapati 提问时间:11/17/2023 更新时间:11/17/2023 访问量:36
在搜索栏上搜索关键字时,显示数据后再次键入另一个关键字未显示显示错误,未找到数据,您可以告诉我[关闭]
when search a keyword on search bar data show after again type another keyword not show show me error no data found can you tell me [closed]
问:
当我使用一个 keyowrd 数据显示时,如何一次搜索多个关键字,然后再次搜索另一个关键字数据未显示
我的代码在下面
public function searchData($searchVal){
try {
$dbConnection = $this->dbConnect();
$stmt = $dbConnection->prepare("SELECT * FROM `tb_report` WHERE `product` like :searchVal OR `maintitle` like :searchVal ORDER BY `id` DESC LIMIT 15");
$val = "%$searchVal%";
$stmt->bindParam(':searchVal', $val, PDO::PARAM_STR);
$stmt->execute();
$Count = $stmt->rowCount();
$result ="" ;
if ($Count > 0){
$result='<div class="left_cat_name"> Reports</div>';
while($data=$stmt->fetch(PDO::FETCH_ASSOC)) {
$result = $result .'<div class="search-result2"><a class="fineword" href="'.'https://www.website.com/'.$data['product_url'].'/'.'">'.$this->highlightWords($data['product'],$searchVal).'</a></div>';
//$result = $result .'<div class="search-result2"><a class="fineword" href="'.'https://www.website.com/'.$data['product_url'].'">'.$data["product"].'</a></div>';
}
$result .= '<button class="btn btn-default custom-btn" id="view-result" onclick="myFunction()">View Full Results</button>';
$result .= '<button class="btn btn-default custom-btn" id="viewresultmob" onclick="mobilekey()">View Full Results</button>';
return $result;
}
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
我需要你的帮助,你能告诉我它是如何工作的吗
答: 暂无答案
评论
foo bar
like :searchVal
foo
bar
WHERE field LIKE '%foo%' OR field LIKE '%bar%'
tb_report
product
maintitle
id