I am trying to run the below query, I've figured out the SET statements are a separate query to the SELECT query. I've found a few answers relating to this but cant get them to work in my code.
It all works fine in phpMyAdmin but not in this PHP webpagepage
How do i go about running the 2 queries to get the result?
$queryRank = "SET @rnk=0; SET @rank=0; SET @curscore=0;
SELECT rank FROM
(
SELECT AA.*,BB.playerId,
(@rnk:=@rnk+1) rnk,
(@rank:=IF(@curscore=best3,@rank,@rnk)) rank,
(@curscore:=best3) newscore
FROM
(
SELECT * FROM
(SELECT COUNT(1) scorecount,best3
FROM leaderboard GROUP BY best3
) AAA
ORDER BY best3 DESC
) AA LEFT JOIN leaderboard BB USING (best3)) A
WHERE playerId='$memberID'";
$resultRank = mysqli_query($link, $queryRank);
if (mysqli_num_rows($resultRank) > 0) {
$rowRank = mysqli_fetch_array($resultRank);
echo "<p class='mt-2 statNumber'>".$rowRank['rank']."</p>";
} else {
echo "No events played";
}