Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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
MySQL条件_Mysql_Conditional Statements - Fatal编程技术网

MySQL条件

MySQL条件,mysql,conditional-statements,Mysql,Conditional Statements,我还是MySQL的新手,我不知道最好的方法 我有一个带有递增值的表,如果值超过某个限制,我想知道。假设这个表有一个current列和capacity列。current中的一行通过用户输入递增,我想知道current行中的值何时超过或满足其相应的容量 如果当前仍低于容量,我希望查询返回true。但是,如果当前满足或超过容量,我希望查询返回false 谢谢 在mysql中,这很简单: select (current >= capacity) as exceeded from table 添加

我还是MySQL的新手,我不知道最好的方法

我有一个带有递增值的表,如果值超过某个限制,我想知道。假设这个表有一个
current
列和
capacity
列。
current
中的一行通过用户输入递增,我想知道
current
行中的值何时超过或满足其相应的
容量

如果
当前
仍低于
容量
,我希望查询返回true。但是,如果
当前
满足或超过
容量
,我希望查询返回false

谢谢

在mysql中,这很简单:

select (current >= capacity) as exceeded from table

添加一个
WHERE
子句以在
UPDATE
查询中执行该检查:

// I assume you mean you want to increment the current column by 1,
// but it's your table so change the SET values as needed
$updated = mysql_query('UPDATE table SET current = current + 1 WHERE id = ' . intval($row_id) . ' AND current < capacity');
if (mysql_affected_rows() > 0)
{
    // Success
}

=>现在是MySQL中的有效运算符,还是您的意思是>=?这不应该只在
当前
时返回true吗?谢谢您的回复。实际上,我正在对行使用更新。如何将其应用于更新查询?谢谢谢谢这正是我需要的。不过,我有一个问题。每当我将与我的
mysql\u查询相关联的变量放入
mysql\u受影响的行中时,它都不会工作(表示它不是有效的mysql资源)。当我删除它并在没有参数的情况下使用
mysql\u impacted\u rows()
时,它成功了!你知道为什么吗??谢谢因为这是我的一个错误:变量不应该存在。我已编辑我的答案以删除它。抱歉搞混了!很高兴我的解决方案对您有效:)