我正在尝试绑定ORDER BY的值以获得按分数或添加日期排序的选项,但是当我尝试按值绑定顺序时,它会按ID返回标准顺序并且不会监听我的命令
下面是我的代码,我用查询替换了查询中的得分部分?并赋予它一个价值,但它没有用。
<?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>";
}
?>