I have a database with some business categories in it. I am trying to pass a variable from one page to another then run a mysql_query on that value. When the query runs I get a "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource"

I assume this is because I have some spaces between some of the values of the category field.

Example...Food & Dining, Home & Garden, etc...

I used urlencode($category) to remove the spaces on the first page but I am not sure how / or what to do with the mysql query. I have also tried single quotes versus double qoutes arond the value.

Thanks for any suggestions.

First page code (A list of all categories):

<?php

   $result = mysql_query("SELECT category, cat_id FROM CATEGORIES order by category");
   echo "<table id='cat-table' border=\"0\" cellpadding=\"3\" cellspacing=\"5\"><tr>";
   $i = 0;
   while($array = mysql_fetch_array($result)){//loop through

$i++;
$category = $array["category"];

  echo "<td width=\"303\">". "<img src='images/category-bullet.png' width=\"5\" height=\"15\" />".'  '. "<a href='view-category.php?category="  .urlencode($category). "'/>"   .$array['category']. "</td>";   


 if($i == 3){echo "</tr><tr>";$i=0;}
   } 

$num_rows = mysql_num_rows($result);
$find_colspan = 3 - ($num_rows%3);
for($i=0;$i<$find_colspan;$i++){
echo "</td>";
}
      echo "</tr></table>";
     echo "<br/>";
?>

Second page code(view-category.php):

   <?php
   $category = $_GET["category"];
   //$category = urlencode($category);

   //echo $category;

   $result2 = mysql_query("SELECT category FROM TEST WHERE category=$category");
   $row2 = mysql_fetch_array ($result2);
   echo "<strong>Results for the $row2[category] category are listed below.</strong>";
   echo "<br/><br/>";


   $result = mysql_query("SELECT * FROM TEST WHERE category=$category");
   while($row = mysql_fetch_array($result))  {

  echo $row['business_name']. "<br/>";
  echo $row['address']. "<br/>";
  echo $row['city']. ', '. $row['state']. ' '.$row['zip'];      
  echo "<br/><br/>";
   }

?>
    $query = "SELECT * FROM TEST WHERE category='" . mysql_real_escape_string($category) . "'";
    $result = mysql_query($query);
    
      Write a Reply...