开发者

PHP mysql_num_rows() usage on INNER JOIN query

<?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";
    }
}

?>

So when setting the condition in the if-else statement I tried several ways to catch the $rowCount value of 0 but it just开发者_如何学JAVA doesn't seem to work for me.

Does my query need to be using syntax that eliminates null joins or how do I identify when $rowCount = 0 ?


The loop while(false) { } will never execute, and that's what you have when there are no rows. You have to put the check for $row_count outside the while-loop:

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

else
{
  while ($row = mysql_fetch_array($sql)) { ... }
}


If your Statement has nothing returned, the while loop will never be entered. The expression $row=mysql_fetch_array($sql) will evaluate to true only if there was a row fetched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜