function getGamesBySearch($criteria) {
try {
$sortedBy = 'Name';
$db = getDBConnection();
$query = "SELECT *
FROM game
WHERE Name LIKE :criteria
ORDER BY :sortBy DESC";
$statement = $db->prepare($query);
$statement->bindValue(':criteria', '%'.$criteria.'%');
$statement->bindValue(':sortBy',$sortedBy);
$statement->execute();
$results = $statement->fetchAll();
$statement->closeCursor();
return $results; // Assoc Array of Rows
} catch (PDOException $e) {
$errorMessage = $e->getMessage();
include '../view/errorPage.php';
die;
}
}
出于某种原因,我的关联数组总是以我的 GameID 顺序返回,当我需要它按照名称的顺序时?这只是我正在上课的奖励,但我们将不胜感激。