dongzhuan1185 2014-10-18 21:48
浏览 30
已采纳

如何获得一个在PHPmyadmin中工作的mysql脚本,以便在PHP mysql查询中工作?

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!!

  • 写回答

1条回答 默认 最新

  • dongwai4434 2014-10-18 22:02
    关注

    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;") ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动