php+;mysql\u num\u行问题?
我有一个简单的sql语句,我想根据返回的行数执行不同的操作php+;mysql\u num\u行问题?,php,mysql,Php,Mysql,我有一个简单的sql语句,我想根据返回的行数执行不同的操作 $result_lists = mysql_num_rows(mysql_query("SELECT * FROM db_table")); //To see the number returned print_r($result_lists); switch($result_lists) { case($result_lists == 0): //To prove whic
$result_lists = mysql_num_rows(mysql_query("SELECT * FROM db_table"));
//To see the number returned
print_r($result_lists);
switch($result_lists) {
case($result_lists == 0):
//To prove which option is actually happening
print_r('lists==0: '.$result_lists);
break;
case($result_lists > 1):
//To prove which option is actually happening
print_r('lists>1: '.$result_lists);
break;
case($result_lists == 1):
//To prove which option is actually happening
print_r('lists==1: '.$result_lists);
break;
}
如果找到一行或多行,则使用正确的大小写,但是,如果返回零行,则出于某种原因执行(>1)大小写
有人能看出哪里出了问题吗
谢谢你的建议
谢谢。返回零或null,您有支票
case($result_lists == 0 or null):
或许
case(empty($result_lists)):
返回零或null,您必须进行检查
case($result_lists == 0 or null):
或许
case(empty($result_lists)):
你不应该那样使用开关
switch($var)
{
case 1:
//Some stuff
break;
case 2:
//Some stuff
break;
default:
break;
}
这是正确的做法。用ifs和ELSE去做,yadayda!你的虫子会消失
为什么??因为
case
不是用来计算语句的。它只比较开关中的内容
与案例中的内容
您不应该这样使用开关
switch($var)
{
case 1:
//Some stuff
break;
case 2:
//Some stuff
break;
default:
break;
}
这是正确的做法。用ifs和ELSE去做,yadayda!你的虫子会消失
为什么??因为
case
不是用来计算语句的。它只比较开关中的内容
与案例中的内容
您滥用了开关语句-如果s,则应将其替换为,或按如下方式更改:
switch ($result_lists)
{
case 0:
//To prove which option is actually happening
print_r('lists==0: '.$result_lists);
break;
case 1:
//To prove which option is actually happening
print_r('lists==1: '.$result_lists);
break;
default:
//To prove which option is actually happening
print_r('lists>1: '.$result_lists);
break;
}
case($result_lists == 0):
// is like doing
if ($result_lists == ($result_lists == 0))
// which when $result_lists = 0 is the same as
if ($result_lists == true)
if (0 == 1)
// therefore false so it drops through to the next statement
case($result_lists > 1)
// the same as
if ($result_lists == ($result_lists > 1))
// when $result_lists = 0:
if ($result_lists == false)
if (0 == 0)
你现在做的是这样的:
switch ($result_lists)
{
case 0:
//To prove which option is actually happening
print_r('lists==0: '.$result_lists);
break;
case 1:
//To prove which option is actually happening
print_r('lists==1: '.$result_lists);
break;
default:
//To prove which option is actually happening
print_r('lists>1: '.$result_lists);
break;
}
case($result_lists == 0):
// is like doing
if ($result_lists == ($result_lists == 0))
// which when $result_lists = 0 is the same as
if ($result_lists == true)
if (0 == 1)
// therefore false so it drops through to the next statement
case($result_lists > 1)
// the same as
if ($result_lists == ($result_lists > 1))
// when $result_lists = 0:
if ($result_lists == false)
if (0 == 0)
您正在滥用switch语句-应将其替换为if
s,或按如下方式更改:
switch ($result_lists)
{
case 0:
//To prove which option is actually happening
print_r('lists==0: '.$result_lists);
break;
case 1:
//To prove which option is actually happening
print_r('lists==1: '.$result_lists);
break;
default:
//To prove which option is actually happening
print_r('lists>1: '.$result_lists);
break;
}
case($result_lists == 0):
// is like doing
if ($result_lists == ($result_lists == 0))
// which when $result_lists = 0 is the same as
if ($result_lists == true)
if (0 == 1)
// therefore false so it drops through to the next statement
case($result_lists > 1)
// the same as
if ($result_lists == ($result_lists > 1))
// when $result_lists = 0:
if ($result_lists == false)
if (0 == 0)
你现在做的是这样的:
switch ($result_lists)
{
case 0:
//To prove which option is actually happening
print_r('lists==0: '.$result_lists);
break;
case 1:
//To prove which option is actually happening
print_r('lists==1: '.$result_lists);
break;
default:
//To prove which option is actually happening
print_r('lists>1: '.$result_lists);
break;
}
case($result_lists == 0):
// is like doing
if ($result_lists == ($result_lists == 0))
// which when $result_lists = 0 is the same as
if ($result_lists == true)
if (0 == 1)
// therefore false so it drops through to the next statement
case($result_lists > 1)
// the same as
if ($result_lists == ($result_lists > 1))
// when $result_lists = 0:
if ($result_lists == false)
if (0 == 0)
请不要那么快验证答案,让人们回答。顺便说一句,这个答案可能有用,但它仍然是一个糟糕的答案。请不要那么快验证答案,让人们来回答。顺便说一句,这个答案可能有用,但它仍然是一个糟糕的答案。switch语句不是这样工作的。回答不好,对我来说是-1。switch语句不是这样工作的。回答不好,对我来说是-1。+1比我给出的解释多。如果可能的话,我会为机器人外观的代码行添加+1:if(0==0)
:D+1以获得比我给出的更多的解释。如果可以的话,我会为机器人外观的代码行添加+1:if(0==0)
:D