为什么当我在PHP文件中运行此查询时,我什么都没得到。任何建议。
当我在SQL phpMyAdmin中运行相同的代码时,它正常工作。我需要帮助,如何编辑我的代码才能运行。
$sql = "SET @prev_value = NULL;";
$query = mysqli_query($connection,$sql) or trigger_error("Query Failed: " . mysqli_error($connection));
$sql = "SET @rank_count = 0;";
$query = mysqli_query($connection,$sql) or trigger_error("Query Failed: " . mysqli_error($connection));
$sql = "SELECT *,
CASE
WHEN @prev_value = totalPoints THEN @rank_count
WHEN @prev_value := totalPoints THEN @rank_count := @rank_count + 1
ELSE @rank_count := @rank_count + 1
END AS userRank
FROM resultsTestDB
ORDER BY totalPoints;";
$query = mysqli_query($connection,$sql) or trigger_error("Query Failed: " . mysqli_error($connection));
$data = mysqli_fetch_assoc($query);
for ($i=0; $i<sizeof($data); $i++){
if ($data[$i]['memberID']==$memberID)
$myRank = $data[$i]['userRank'];
}
return $myRank;