MySQL query

I have written a query and code to interpret the response however I must be missing something as my result always comes up and being empty and I know it is not. Can you look over my code with a fresh pair of eyes and spot where I am going wrong?

echo "<p>Please choose a category:</p>";
  ///set the variable
     $masterCat = "clothing";
    // make the function
	  function masterCat($catid) {
   // query database for the books in a category
   $conn = db_connect();
   $query = "select * from catagories where masterCat = '".$masterCat."'";
   $result = @$conn->query($query);
   if (!$result) {
     return false;
   $num_items = @$result->num_rows;
   if ($num_items == 0) {
      return false;
   $result = db_result_to_array($result);
   return $result;

  $masterCat_array = masterCat($masterCat);

  //display all books in the array passed in
  if (!is_array($masterCat)) {
    echo "<p>No products currently available in this category</p>";
  } else {
    //create table
    echo "<table class=\"tclass\" width=\"100%\" border=\"0\">";

    //create a table row for each book
    foreach ($catname as $row) {
      $url = "show_product.php?isbn=".$row['isbn'];
      echo "<tr><td>";
      if (@file_exists("images/".$row['isbn'].".jpg")) {
        $title = "<img src=\"images/".$row['isbn'].".jpg\"
                  style=\"border: 1px solid black\"/>";
        do_html_url($url, $title);
      } else {
        echo "&nbsp;";
      echo "</td><td>";
      $title = $row['title'];
      do_html_url($url, $title);
      echo "</td></tr>";

    echo "</table>";

  echo "";

Open in new window

Neil_BradleyWeb UX/UI DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Maybe like this:
"select * from catagories where masterCat = '" & $masterCat & "'";
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
No, doesnt fix it.  The vaiiarble "clothing" was chose to thest the system as it is definatly there.
Dave BaldwinFixer of ProblemsCommented:
I don't find 'db_result_to_array' in PHP.  Could you mean 'mysql_fetch_array' or 'mssql_fetch_array'?  You put MySQL in your title and MSSQL as one of your zones.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

"select * from catagories where masterCat = '$masterCat'";

i.e. $masterCat surrounded by single quotes and entire query overall by double quotes.

PHP Variable in mySQL query
MySQL :: how to use PHP variable in MYSQL query?,1237823702,older
Pass a php variable to mysql query
PHP MySQL by examples

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
My bad:
"select * from catagories where masterCat = '" & $masterCat & "';"

After the ampresand it should have been:
double, single, semi, double
Dave BaldwinFixer of ProblemsCommented:
Is 'catagories' the correct spelling for your table name?  categories?
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Thats got it.. Brilliant thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.