Php Can';我不能将LIKE添加到我的SQL查询中
我希望最终将我的搜索框与此查询挂钩,但此查询不起作用,我已尝试将alter查询添加到以下内容中以进行测试:Php Can';我不能将LIKE添加到我的SQL查询中,php,sql,Php,Sql,我希望最终将我的搜索框与此查询挂钩,但此查询不起作用,我已尝试将alter查询添加到以下内容中以进行测试: include("config.php"); $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); if(!is_numeric($page_number)){ header('HTTP/1.1 500 Invalid page number!');
include("config.php");
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
if(!is_numeric($page_number)){
header('HTTP/1.1 500 Invalid page number!');
exit();
}
session_start();
$position = (($page_number-1) * $item_per_page);
if(!empty($_SESSION['type'])){
$typesql = $_SESSION['type'];
$results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE type = ? ORDER BY score DESC LIMIT ?, ?");
$results->bind_param("sii", $typesql, $position, $item_per_page);
$results->execute();
$results->bind_result($name, $location, $score, $img, $id, $type);
} else {
$results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists ORDER BY score DESC LIMIT ?, ?");
$results->bind_param("ii", $position, $item_per_page);
$results->execute();
$results->bind_result($name, $location, $score, $img, $id, $type);
}
// Le fetch
while($results->fetch()){
//my cards here
}
?>
我确实有一个名字里面有“etc”,但我得到的结果是:
SELECT name, location, score, img, id, type FROM artists WHERE name LIKE '%etc%' ORDER BY score DESC LIMIT ?, ?
如何更改此查询以将$\u GET result from searchbox绑定到该查询,该网站是Setch.me,因为您可以在mysqli中使用带有绑定参数的LIKE
:
Call to a member function bind_param() on boolean in
您有一个输入错误:例如“%etc%”由于您在比较后缺少一个而导致的订单。请使用
LIKE?
并添加%etc%
作为参数。注意,如果遇到非数字页码,您应该以400而不是500的状态退出。记住,4xx是“你搞砸了”,5xx是“我搞砸了”。在参数中添加%太棒了,谢谢你,伙计。
$param = "%{$_POST['searchphrase']}%";
$stmt = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE name LIKE ?");
$stmt->bind_param("s", $param);
$stmt->execute();
$stmt->bind_result($name, $location, $score, $img, $id, $type);