代码之家  ›  专栏  ›  技术社区  ›  Kareem Kamal

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

  •  1
  • Kareem Kamal  · 技术社区  · 9 年前
    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
    

    1 回复  |  直到 9 年前
        1
  •  2
  •   WEBjuju Douglas Harris    9 年前

    this question LIKE 在mysqli中使用绑定参数:

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