繁体   English   中英

无法将LIKE添加到我的SQL查询中

[英]Can't add LIKE to my SQL query

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
  }
  ?>

我正在寻找最终使我的搜索框挂接到该查询,但该查询不起作用,我试图将更改查询添加到以下内容中以进行测试:

SELECT name, location, score, img, id, type FROM artists WHERE name LIKE '%etc%' ORDER BY score DESC LIMIT ?, ?

而且我确实有一个带有“ etc”的名称,但是得到的结果是:

Call to a member function bind_param() on boolean in

我如何更改此查询以将$ _GET结果从搜索框绑定到该查询,该网站为Setch.me

就像这个问题一样,您可以在mysqli中将LIKE与绑定参数一起使用:

$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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM