我遇到了将LIKE与Wildcard绑定到我在
MySQLi中准备好的语句的问题.我尝试了以下两种方法,如图所示& concat.(用@fancyPants输入更新)
>有没有办法让我可以在绑定发生后查看自己的sql语句?
>如何正确绑定它以获得我想要的结果?
它没有LIKE语句.
$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,$bookPrice); while ($stmt->fetch()) { echo $bookTitle; }