开发者

Can't add 1 to a user-variable in SQL incrementally

It's possibly due to the variable @count not being recognised as an integer but开发者_如何学Go in my research I've come across many example similar to @count = @count + 1; That's why I'm confused as to why this breaks my code when introduced:

$setCount = "SELECT @count:=5";
$uncategorise = "UPDATE pictures
    SET category = '0',
    pictureorder = @count,
    @count:=@count+1
    WHERE category = '$categoryID'
    AND username = '$username';
$queryCount = mysql_query($setCount) or die(mysql_error());
$queryUncat = mysql_query($uncategorise) or die(mysql_error());


because this is an user defined variable,
which only stand/available for the same session/connection

You can store a value in a user-defined variable in one statement and then refer to it later in another statement. This enables you to pass values from one statement to another. User-defined variables are connection-specific. That is, a user variable defined by one client cannot be seen or used by other clients. All variables for a given client connection are automatically freed when that client exits.

There is an easy solution -- php mysqli_multi_query


You could create a field in the DB that does the counting and then retrieve the data from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜