error in where clause

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
billybongchong
Forum Newbie
Posts: 5
Joined: Tue Nov 04, 2003 5:01 pm
Location: Australia

error in where clause

Post by billybongchong »

have a function to select data from a mysql database with a join. (php)

I am having trouble in the where variable giving me a MYSQL error - "uknow column 'yes' in where clause". All is working correctly but when I add the active - column to the query i get the error.

The problem is that I do not want this part of the where clause to check between columns but to see if column p.active = "yes"... Is there a way that I can make the where clause detect this without referencing between the two tables while leaving the other two clauses functioning as part of this function?

Any Help would be muchly appreciated.

Code: Select all

<?php

// run function
$qid_p = get_products($id,$yes);

function get_products($category_id=0, $yes) {
/* get all the products under this category */

     $qid = db_query("
      SELECT
                 p.id
               ,p.name
                ,p.description
                ,p.price
                ,p.on_special
                ,p.image
            ,p.author
            ,p.isbn
                ,p.pages
                ,p.type
                ,p.in_stock
                ,p.active
                ,pc.category_id
        FROM
                 products p
              ,products_categories pc
       WHERE p.active = $yes
     AND p.id = pc.product_id
             AND pc.category_id = $category_id
             ");

        return $qid;

} 

?>
[/php_man]
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

Code: Select all

<?php
/ run function 
$qid_p = get_products($id,$yes); 

function get_products($category_id=0, $yes) { 
/* get all the products under this category */ 

     $qid = db_query(" 
      SELECT 
         ...
         ...
        FROM 
          ....
       WHERE p.active = '$yes' 
     AND p.id = pc.product_id 
             AND pc.category_id = '$category_id'
             "); 

        return $qid; 

} 
?>
may solve the problem
just put " ' " around the $yes
Post Reply