Update single column of table and value should start from 0 and then should increment by 1

柔情痞子 提交于 2019-12-11 10:49:36

问题


$sqlcount1 ="SET uid = -1 UPDATE `agent_normal` SET `uid` = @a:=@a+1";
$result = mysqli_query($conn,$sqlcount1);

how to write this query in core php?

This query works in mysql but not in core php.

Here i want to update a single row of table and value should start from 0 and then should increment by 1.


回答1:


There are a couple of problems. Firstly, if you look at this answer you'll see you have an incorrect variable name and missing semicolon. The query should be :

$sqlcount1 ="SET @a = -1; UPDATE `agent_normal` SET `uid` = @a:=@a+1";

Secondly, to use two queries in one call you need to use mysqli_multi_query.

$result = mysqli_multi_query($conn,$sqlcount1);


来源:https://stackoverflow.com/questions/49827947/update-single-column-of-table-and-value-should-start-from-0-and-then-should-incr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!