Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the fetched array is empty or not PHP?

Tags:

php

mysql

I am trying to check if the mysql_fetch_array() function returns an empty array or not. But my code doesn't seem to work. Here I want to ensure that if the array is empty I want to display under construction message.

Code :

$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
   }
}

How do I check to acheive such feature ?

like image 886
monk Avatar asked Nov 28 '22 09:11

monk


2 Answers

use mysql_num_rows to count number of rows. try this.

$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

   }
}
like image 180
pahan Avatar answered Dec 10 '22 04:12

pahan


You really should be using mysql_num_rows http://us2.php.net/manual/en/function.mysql-num-rows.php

However, on a side note, you should use php empty() instead. http://us2.php.net/empty

like image 20
jeremy Avatar answered Dec 10 '22 04:12

jeremy