Php 不能通过以下方式绑定订单?
我试图绑定ORDER BY的值,使其具有按分数或添加日期排序的选项,但是,当我尝试绑定ORDER BY值时,它将返回到标准的ORDER BY id,并且不听取我的命令 下面是我的代码,我已将查询中的分数部分替换为?给了它一个值,但它不起作用Php 不能通过以下方式绑定订单?,php,mysql,Php,Mysql,我试图绑定ORDER BY的值,使其具有按分数或添加日期排序的选项,但是,当我尝试绑定ORDER BY值时,它将返回到标准的ORDER BY id,并且不听取我的命令 下面是我的代码,我已将查询中的分数部分替换为?给了它一个值,但它不起作用 <?php include("config.php"); $page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH); i
<?php
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);
$search = "%{$_SESSION['search']}%";
$city = $_SESSION['city'];
if(isset($_SESSION['type'])){
$typesql = $_SESSION['type'];
}
if(isset($_SESSION['type2'])){
$typesql2 = $_SESSION['type2'];
}
if(empty($_SESSION['type']) && empty($_SESSION['type2'])){
$typesql = 'photographer';
$typesql2 = 'makeup artist';
}
if($city=='Alexandria' || $city=='Cairo'){
$results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE CONCAT(name, location) LIKE ? AND visible='yes' AND type IN(?, ?) AND location IN(?) ORDER BY score DESC LIMIT ?, ?");
$results->bind_param("ssssii", $search, $typesql, $typesql2, $city, $position, $item_per_page);
}else{
$results = $mysqli->prepare("SELECT name, location, score, img, id, type FROM artists WHERE CONCAT(name, location) LIKE ? AND visible='yes' AND type IN(?, ?) ORDER BY score DESC LIMIT ?, ?");
$results->bind_param("sssii", $search, $typesql, $typesql2, $position, $item_per_page);
}
$results->execute();
$results->bind_result($name, $location, $score, $img, $id, $type);
// Le fetch
while($results->fetch()){
echo "<div class=\"card feed_item\" style=\"width: 20rem;\"><a id=\"wraplink\" href=\"profile.php?id=". $id."\">";
echo "<div class=\"imgcont\"><img class=\"card-img-top feed_img\" src=\"img/" . $img . ".jpg\"></div>";
echo "<div class=\"card-block\">";
echo "<h4 class=\"card-title\">" . $name . "</h4>";;
echo "</div><div class=\"card-footer ";
if($type=="Photographer"){
echo "footerph";
}else{
echo "footermk";
}
echo "\"><small class=\"text-muted\"><b>". $type;
if($city=="Egypt"){
echo " from ". $location;
}
echo "</b></small><span class=\"fb-comments-count\" data-href=\"http://setch.me/profile.php?id=".$id."\"></span></div></a></div>";
}
?>
to bind ORDER by's value”的确切含义是什么?您不能使用bind_param()
来绑定列名。您应该使用PDO,而不是mysqli。但是,您还试图将6个参数绑定到4个占位符。}else{$results=$mysqli->prepare(“选择名称、位置、分数、img、id,从艺术家那里输入,其中CONCAT(名称、位置)类似于?和visible='yes',并按分数描述限制的顺序键入?”);$results->bind_参数(“sssii”、$search、$typesql、$typesql2、$position、$item_per_page);)很高兴看到php代码看起来仍然和15年前一样。