本文介紹了mySqli 綁定參數(shù) 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)
有沒有辦法在綁定發(fā)生后查看自己的 SQL 語句?
Is there a way so that I can view my own SQL statement after the binding happens?
如何正確綁定以獲得我想要的結(jié)果?
How do I bind it properly to get the result I want ?
它可以在沒有 LIKE 語句的情況下工作.
It works without the LIKE statement.
我只能從使用某個搜索詞中提取數(shù)據(jù).我的代碼有問題嗎?
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;
}
這篇關(guān)于mySqli 綁定參數(shù) LIKE 與通配符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!