[英]what's wrong with this function?
function get_ibo_id() {
if($registerquery = $this->conn->query("SELECT ibo_id FROM fasttrack WHERE count <
8 && flag = 1 ")){
$this->increase_count();
while ($row = $registerquery->fetch_assoc()) {
return $row[ibo_id];
}
}
else return "No id";
}
it always enters the if block even if the condition is not satisfied... going crazy 即使不满足条件,它也总是进入if块... 发疯
Well $registerquery will never return false, even if you condition is not met... 好$ registerquery永远不会返回false,即使您的条件不满足...
in if statements you have to get a variable to return true or false... 在if语句中,您必须获取一个变量以返回true或false ...
What I would do is something like this (you will have to adept it to your OOP code): 我要做的是这样的事情(您必须将其熟练应用于OOP代码):
function get_ibo_id() {
$registerquery = $this->conn->query("SELECT ibo_id FROM fasttrack WHERE count < 8 && flag = 1 ");
if (mysql_num_rows($registerquery) > 0) {
$this->increase_count();
while ($row = $registerquery->fetch_assoc()) {
return $row[ibo_id];
}
}
else return "No id";
}
It makes a query,checks if you get more than 0 results back and does what is has to do, otherwise echo's an error... 它进行查询,检查返回的结果是否超过0,并执行必须执行的操作,否则echo是一个错误...
Ladislav 拉吉斯拉夫
I think the problem is that 我认为问题是
$this->conn->query(...)is not returning FALSE as you might expect.
mysql_num_rows($registerquery)mysql_num_rows($ registerquery)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.