Reputation: 55
Hello i have a small php query i run that updates multiple rows in my table.
SET @rank = 0;
UPDATE Summoner_Champions SET Rank = (@rank := @rank + 1)
WHERE Champion_ID=0
ORDER BY Total DESC
When i try and use the following php code, it doesnt work
$Ranker_Sql = "SET @rank = 0;
UPDATE Summoner_Champions SET Rank = (@rank := @rank + 1)
WHERE Champion_ID=0
ORDER BY Total DESC";
if ($Conn_Info->query($Ranker_Sql) === TRUE) {
echo " Total Updated ";
}
else {
echo mysqli_error($Conn_Info);
echo "Total Not Updated";
}
I tried using an alternative query and it worked, such as a super simple update, so the connection info is correct.
Thank you for reading, and for the help :)
Edit 1: Tried the query using PDO, still did not seem to work. Tried to find resources online that could help me with using sql variables in php sql queries but alas found nothing.
Upvotes: 2
Views: 336
Reputation: 55
Solved, i had to declare the sql variable in a seperate sql query, then i was free to use it in my query :).
Like this.
$Pre_Sql = "SET @rank =0";
$dbc->query($Pre_Sql);
$Normal_Sql = "UPDATE Summoner_Champions SET Rank = (@rank := @rank + 1)
WHERE Champion_ID=0
ORDER BY Total DESC";
$dbc->query($Normal_Sql);
Upvotes: 1