英文:
Codeigniter : stop the while function when value '0'
问题
如何在我已经将数量更新为'0'后停止“while”循环?
$check = $this->db->query("SELECT *
FROM tmp_headik2
WHERE no_bukti = '$no_bukti' AND qty > '0'");
while($check->num_rows() > 0)
{
$this->db->query("UPDATE tmp_headik2
SET qty = '0'
WHERE no_bukti = '$no_bukti'");
}
return $check->result_array();
"while"函数仍然循环。
英文:
How the "while" can stopped when i'm already update qty to '0' ?
$check = $this->db->query("SELECT *
FROM tmp_headik2
WHERE no_bukti = '$no_bukti' AND qty > '0'");
while($check->num_rows() > 0)
{
$this->db->query("UPDATE tmp_headik2
SET qty = '0'
WHERE no_bukti = '$no_bukti'");
}
return $check->result_array();
The while function still loop
答案1
得分: 1
欢迎来到Stack Overflow
我对$check->num_rows()
正在做什么有一点疑问,但我认为在你的情况下,可能不真正需要使用while
。
可能你可以用一个if
来替换它吗?因为我缺少一些关于你的代码正在做什么的上下文,所以这可能不正确。请告诉我。
基本上,while
会执行内部的代码,直到条件$check->num_rows() > 0
为false
。这意味着你的$this->db->query(...)
调用会一遍又一遍地执行,直到条件不再满足。
我还觉得有点奇怪的是你的$this->db->query(...)
调用总是相同的,所以我会假设在第一次执行后再次调用它不会做任何不同的事情。
你可以再检查一下这个对你是否有效?
if ($check->num_rows() > 0)
{
$this->db->query("UPDATE tmp_headik2
SET
qty = '0'
WHERE no_bukti = '$no_bukti'
");
}
return $check->result_array();
英文:
welcome to stackoverflow
I am missing a bit of information on what $check->num_rows()
is doing, but I believe that you don't really need a while
in your case.
Probably you can replace it with an if
? Since I am missing a bit of context of what your code is doing this might not be correct. Let me know.
Basically the while
will be executing the code inside until the condition $check->num_rows() > 0
is false
. This means that your $this->db->query(...)
call will be done again and again until then.
I find it also a bit strange that your $this->db->query(...)
call is the same always, so I would assume that after the first time it is executed calling it a second time would do anything else.
Can you double check if this works for you?
if( $check->num_rows() > 0 )
{
$this->db->query("UPDATE tmp_headik2
SET
qty = '0'
WHERE no_bukti = '$no_bukti'
");
}
return $check->result_array();`
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论