检查获取的数组是否为空或不是PHP?

mon*_*onk 4 php mysql

我试图检查mysql_fetch_array()函数是否返回一个空数组.但我的代码似乎不起作用.在这里,我想确保如果数组为空,我想在构造消息下显示.

代码:

$queryContents= queryMembers();
$exeQuery = mysql_query($queryContents);
while($fetchSet = mysql_fetch_array($exeQuery)) {
   if(count($fetchSet) == 0) {
     echo "This Page is Under Construction";
   }else{
     // something else to display the content
   }
}
Run Code Online (Sandbox Code Playgroud)

如何检查以实现此功能?

pah*_*han 14

使用mysql_num_rows来计算行数.试试这个.

$exeQuery = mysql_query($queryContents);

if(mysql_num_rows($exeQuery)== 0){
   echo "This Page is Under Construction";
}
else{
   while($fetchSet = mysql_fetch_array($exeQuery)) {

     // something else to display the content

   }
}
Run Code Online (Sandbox Code Playgroud)


jer*_*emy 5

你真的应该使用mysql_num_rows http://us2.php.net/manual/en/function.mysql-num-rows.php

但是,在旁注中,您应该使用php empty()代替.http://us2.php.net/empty