-1

i am getting this error as i was trying free classified script on http://www.tutorialized.com/tutorial/Create-Classifieds-Software-In-1-Hour/60523

this is the code and line 47

enter code here  
function list_count()
   {
       $q="SELECT COUNT(tA.id) as classifieds, tC.name as name, tC.id as id
       FROM categories as tC LEFT JOIN classifieds as tA ON tA.category_id=tC.id
       ORDER BY tC.name";
       $result=mysql_query($q);
       $cats=array();

   line 47->    while($cat=mysql_fetch_array($result)) $cats[]=$cat;
       return $cats;
   }
ninad
  • 1

2 Answers2

0

It means $result is getting a boolean value instead of resource type which it should have been if it was a succesful query.

So,there is some problem with the query.First check if the $result is not 'false' by a if statement and print the error using mysql_error() if its in fact false.

<?php
    if($result)
    {
        //Proceed with your previous code
    }else{
        echo "Query Failed, Reason :: ".mysql_error();
    }

Then you can proceed to mysql_fetch_array() as in your code.

0

Your mysql_query return false. Refactor your code;

function list_count()
{
   $q="SELECT COUNT(tA.id) as classifieds, tC.name as name, tC.id as id
   FROM categories as tC LEFT JOIN classifieds as tA ON tA.category_id=tC.id
   ORDER BY tC.name";
   $result = mysql_query($q);
   if($result === FALSE) {
    die("Error occured: " . mysql_error());
   }

   $cats=array();   
   while($cat=mysql_fetch_array($result)) $cats[]=$cat;
   return $cats;
}
Hüseyin BABAL
  • 15,214
  • 4
  • 50
  • 72