0
<?php

$sql=mysql_query("SELECT * FROM  table_one INNER JOIN table_two ON table_one.id = table_two.field_id ORDER BY table_one.id ASC LIMIT 0 , 300");
$rowCount=mysql_num_rows($sql);
while($row=mysql_fetch_array($sql)){
    if($rowCount < 1 || $rowCount=="0" || $rowCount == 0 || $rowCount == NULL || $rowCount == false){
        echo "no information retrieved"; 
    }
    else{
        echo "information retrieved";
    }
}

?>

因此,在 if-else 语句中设置条件时,我尝试了几种方法来捕获 $rowCount 值 0,但它似乎对我不起作用。

我的查询是否需要使用消除空连接的语法,或者如何识别 $rowCount = 0 的时间?

4

2 回答 2

2

循环while(false) { }永远不会执行,这就是没有行时所拥有的。您必须将检查放在$row_countwhile 循环之外:

if ($row_count == 0) { ... no information ... }

else
{
  while ($row = mysql_fetch_array($sql)) { ... }
}
于 2011-08-20T23:10:13.303 回答
0

如果您的 Statement 没有返回任何内容,while则永远不会进入循环。仅当提取了一行时,表达式$row=mysql_fetch_array($sql)才会评估为 true。

于 2011-08-20T23:10:36.267 回答