简体   繁体   中英

How can I get a mysql script that works in PHPmyadmin, to work in a PHP mysql query?

Simple question with i'm sure a simple answer. I have searched around and can't find a solution. Basically my code below works in Phpmyadmin but it wont work in a PHP mysql query script. The code orders my "rank" row by the largest number, and then updates the "position" row with a number, starting at 1 for the greatest number in the "rank" column, and then incrementing the "position" row as the "rank" row values become smaller.

SET @r=0;
UPDATE Data SET position= @r:= (@r+1) ORDER BY rank DESC;
SET @r=0;
SELECT *, @r:= (@r+1) as position FROM Data ORDER BY rank DESC;

Thanks in advance!!

You have multiple queries here. Try using mysqli_multi_query :

$result = mysqli_multi_query($con,"SET @r=0; 
              UPDATE Data SET position= @r:= (@r+1) ORDER BY rank DESC;
              SET @r=0; SELECT *, @r:= (@r+1) as position 
              FROM Data ORDER BY rank DESC;") ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM