0

I'm getting a strange error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u921594465/public_html/category.php on line 71 Prev

This is line 71 from my script:

while ($row1 = mysql_fetch_array($query)) {
   if (isset($_GET['page'])) {
       $page = preg_replace("#[^0-9]#","",$_GET['page']);
   } else {
       $page = 1;
   }
   $perPage = 5;
   $lastPage = ceil($count / $perPage);

   if ($page < 1) {
       $page = 1;
   } else if ($page > $lastPage) {
       $page = $lastPage;
   }
   $limit = "LIMIT " . ($page -1) * $perPage .", $perPage";
   $query = mysql_query("SELECT * FROM post WHERE cat='$nameID' ORDER BY date DESC    $limit");

   if ($lastPage != 1) {
       if ($page != $lastPage) {
           $next = $page + 1;
           $pagination .= '<a href="/category.php?page='.$next.'">Next</a>';
       } 

       if ($page != 1) {
           $prev = $page - 1;
           $pagination .= '<a href="/category.php?page='.$prev.'">Prev</a>';
       }
   }
   while ($row1 = mysql_fetch_array($query)) {
       //LINE 71 HERE
       $output .= $row1['name'] . '<br />';
   }
Sahil Mittal
  • 20,515
  • 12
  • 60
  • 89
Hadscape
  • 35
  • 2
  • 9
  • sounds like you didn't connect to your database correctly or else you would have gotten a resource in return (depending on your query, which you didn't show). http://www.php.net/mysql_query – thescientist Mar 27 '14 at 21:04
  • also, you shouldn't be using mysql – thescientist Mar 27 '14 at 21:05
  • **Before you post a question asking “How do I solve this error?" do a search in the search box for the actual error message.** There you will probably find other questions from people who have had the exact same problem, and then you can learn how they solved it. – Andy Lester Mar 27 '14 at 21:07

1 Answers1

1

You query is returning some error(false), so before fetching the array check if your query is correct and do it something like this-

$result = mysql_query($query);

if($result === FALSE) {
    die(mysql_error()); 
}

while($row = mysql_fetch_array($result))
{
    //...code here
}
Sahil Mittal
  • 20,515
  • 12
  • 60
  • 89
  • http://pastebin.com/B8KwxYEQ he doesn't want to get 'name' from the database, he doesn't want to show it – Hadscape Mar 27 '14 at 21:32