更新表的单列,值应从0开始,然后应增加1 [英] Update single column of table and value should start from 0 and then should increment by 1
本文介绍了更新表的单列,值应从0开始,然后应增加1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$sqlcount1 ="SET uid = -1 UPDATE `agent_normal` SET `uid` = @a:=@a+1";
$result = mysqli_query($conn,$sqlcount1);
如何在核心php中编写此查询?
how to write this query in core php?
此查询在mysql中有效,但在核心php中无效.
This query works in mysql but not in core php.
这里我要更新表的单行,值应从0开始,然后应增加1.
Here i want to update a single row of table and value should start from 0 and then should increment by 1.
推荐答案
有两个问题.首先,如果您查看此 answer ,您会发现变量名不正确和缺少分号.查询应为:
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";
第二,要在一个呼叫中使用两个查询,您需要使用 mysqli_multi_query .
Secondly, to use two queries in one call you need to use mysqli_multi_query.
$result = mysqli_multi_query($conn,$sqlcount1);
这篇关于更新表的单列,值应从0开始,然后应增加1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文