本文介紹了mySqli 綁定參數 LIKE 與通配符的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在將帶有通配符的 LIKE
綁定到 MySQLi 中準備好的語句時遇到問題.我嘗試了以下兩種方法,如下所示 &concat.(更新為@fancyPants 輸入)
I'm having issues binding the LIKE
with Wildcard into my prepared statement in MySQLi. I tried both the following methods below as shown & concat.(updated with @fancyPants input)
有沒有辦法在綁定發生后查看自己的 SQL 語句?
Is there a way so that I can view my own SQL statement after the binding happens?
如何正確綁定以獲得我想要的結果?
How do I bind it properly to get the result I want ?
它可以在沒有 LIKE 語句的情況下工作.
It works without the LIKE statement.
我只能從使用某個搜索詞中提取數據.我的代碼有問題嗎?
I could only pull out data from using a certain search term. Is there anything wrong with my code?
$str = $_POST["searchstr"];
if(isset($_POST['submit']))
{
$price=$_POST['price'];
if(!empty($_POST['chkbx']))
{
foreach($_POST['chkbx'] as $selected)
{
$sql= 'SELECT bookTitle, bookPrice FROM nbc_book WHERE catID LIKE "%'.$selected.'%" AND bookTitle LIKE "%'.$str.'%" AND bookPrice < ?';
$stmt=mysqli_prepare($con,$sql);
mysqli_stmt_bind_param($stmt,"i",$price);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $bookTitle, $bookPrice);
while ($stmt->fetch()) {
echo $bookTitle.$bookPrice."<br>";
}
}
}
}
推薦答案
$searchStr = 'oracle';
$sql= 'SELECT bookTitle, bookPrice FROM nbc_book WHERE catID LIKE ? AND bookTitle LIKE "%'.$searchStr.'%" AND bookPrice < ?';
$stmt=mysqli_prepare($con,$sql);
mysqli_stmt_bind_param($stmt,"ssi",$selected,$price);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $bookTitle, $bookPrice);
while ($stmt->fetch()) {
echo $bookTitle;
}
這篇關于mySqli 綁定參數 LIKE 與通配符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!