开发者

Can I make a MySQL var equal to a MySQL command?

If I perform the following MySQL query through PHP:

UPDATE pictures 
        SET category = '0'
        WHERE category = '$categoryID'
        AND username = '$username'";
$queryUncat = mysql_query($uncategorise) or die(mysql_error());

It works fine and any category that was equal to $categoryID gets changed开发者_如何学Python to 0. However, if I perform the following:

UPDATE pictures 
        SET category = '0',
        pictureorder = (SELECT COUNT(category) + 1 WHERE category='0' AND username='$username')
        WHERE category = '$categoryID'
        AND username = '$username'";
$queryUncat = mysql_query($uncategorise) or die(mysql_error());

Not only does pictureorder not equal to the count of the category row plus one, but the category no longer gets changed if equal to $categoryID. I'm not too good at figuring this out as I know only basic MySQL through PHP and am not familiar with it through its own console.

Thanks in advance for any suggestions.


This form of query is not valid. First, your subquery is missing a FROM clause. Second, you cannot select from the same table you are updating in the same query.

http://dev.mysql.com/doc/refman/5.1/en/update.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜