Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 包含IF语句的查询_Php_Mysql_If Statement - Fatal编程技术网

Php 包含IF语句的查询

Php 包含IF语句的查询,php,mysql,if-statement,Php,Mysql,If Statement,我希望我的查询使用IF语句进行标识;如果当前的num_unmarked在此更新后将变为0,则也将is final设置为“YES” 我的问题是: $sql = "UPDATE results_tb SET num_unmarked = num_unmarked - 1, is_final=IF( num_unmarked-1=0, 'YES', is_fin

我希望我的查询使用IF语句进行标识;如果当前的
num_unmarked
在此更新后将变为0,则也将
is final
设置为“YES”

我的问题是:

 $sql = "UPDATE results_tb 
                    SET 
                        num_unmarked = num_unmarked - 1,
                        is_final=IF( num_unmarked-1=0, 'YES', is_final ),
                        score = score + $awarded
                    WHERE 
                        user_id = $student 
                    AND 
                        test_id = $test 
            ";
实际情况是,查询运行时,num_unmarked递减并更新分数,但是即使num_unmarked为1(不是0),它仍然将is_final设置为“YES”

有没有人能告诉我我做错了什么,或者告诉我一个更好的方法?(我是诺比:D)


谢谢,

更新在MySql中按顺序处理,因此对
num_unmarked
的更新发生在
IF
语句之前,而
IF
语句使用新更新的值。因此,您实际上希望使用该值,就好像它已被更新一样,即直接将其与0进行比较:

is_final = IF(num_unmarked=0, 'YES', is_final),

更新在MySql中按顺序处理,因此对
num_unmarked
的更新发生在
IF
语句之前,而
IF
语句使用新更新的值。因此,您实际上希望使用该值,就好像它已被更新一样,即直接将其与0进行比较:

is_final = IF(num_unmarked=0, 'YES', is_final),