PHP:为什么我不能在这个SQL查询中使用WHERE?

PHP:为什么我不能在这个SQL查询中使用WHERE?,php,sql,Php,Sql,我对sql查询有问题。这是原始功能: function selectAllSorted($active) { return $this->selectObjects("SELECT bp.*, p.title as product_title FROM $this->_table bp INNER JOIN ?_product p USING

我对sql查询有问题。这是原始功能:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp 
                                 INNER JOIN ?_product p USING (product_id)
                                 ORDER BY 0+sort_order,p.title");
}
我将其修改为如下所示:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp
                                 WHERE product_id =$active
                                 INNER JOIN ?_product p USING (product_id)
                                 ORDER BY 0+sort_order,p.title");
}
但是我得到了一个未知的错误,因为我看不到日志,我无法确定它在哪里,或者为什么在这里使用where是错误的

以下是selectObjects函数的定义方式:

function selectObjects($sql, $param1 = null)
    {
        $args = func_get_args();
        $q = call_user_func_array(array($this->_db, 'queryResultOnly'), $args);
        $ret = array();
        while ($row = $this->_db->fetchRow($q))
        {
            $obj = new $this->_recordClass($this);
            $obj->fromRow($row);
            $ret[] = $obj;
        }
        return $ret;
    }
你们能找出问题所在吗


谢谢。

您的语法错误-where子句位于join子句之后:


您的语法错误-where子句位于join子句之后:


您的语法错误-where子句位于join子句之后:


您的语法错误-where子句位于join子句之后:

联接查询syntex是:

Select t1.* from table1 t1
inner join table2 t2  on t1.col1=t2.col1
where t1.col2> 0 and t2.col3>4
现在,您的查询如下所示:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp
                                 INNER JOIN ?_product p on pb.product_id=p.product_id
                                 WHERE bp.product_id =$active                                
                                 ORDER BY 0+sort_order,p.title");
}
联接查询syntex是:

Select t1.* from table1 t1
inner join table2 t2  on t1.col1=t2.col1
where t1.col2> 0 and t2.col3>4
现在,您的查询如下所示:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp
                                 INNER JOIN ?_product p on pb.product_id=p.product_id
                                 WHERE bp.product_id =$active                                
                                 ORDER BY 0+sort_order,p.title");
}
联接查询syntex是:

Select t1.* from table1 t1
inner join table2 t2  on t1.col1=t2.col1
where t1.col2> 0 and t2.col3>4
现在,您的查询如下所示:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp
                                 INNER JOIN ?_product p on pb.product_id=p.product_id
                                 WHERE bp.product_id =$active                                
                                 ORDER BY 0+sort_order,p.title");
}
联接查询syntex是:

Select t1.* from table1 t1
inner join table2 t2  on t1.col1=t2.col1
where t1.col2> 0 and t2.col3>4
现在,您的查询如下所示:

function selectAllSorted($active)
{
    return $this->selectObjects("SELECT bp.*, p.title as product_title
                                 FROM $this->_table bp
                                 INNER JOIN ?_product p on pb.product_id=p.product_id
                                 WHERE bp.product_id =$active                                
                                 ORDER BY 0+sort_order,p.title");
}


移动WHERE子句并将其放置在连接后面谢谢你的回答。移动WHERE子句并将其放置在连接后面谢谢你的回答。移动WHERE子句并将其放置在连接后面谢谢你的回答。移动WHERE子句并将其放置在连接后面谢谢你的回答。可能需要选择来自其中一个表的product_id,即p.productid=…,不是吗?@TomasPastircak是的,很好!在我的答案中添加了bp前缀。谢谢!太快了!我认为顺序无关紧要。可能需要从其中一个表中选择product_id,即p.productid=…,不是吗?@tomaspatircak是的,很好!在我的答案中添加了bp前缀。谢谢!太快了!我认为顺序无关紧要。可能需要从其中一个表中选择product_id,即p.productid=…,不是吗?@tomaspatircak是的,很好!在我的答案中添加了bp前缀。谢谢!太快了!我认为顺序无关紧要。可能需要从其中一个表中选择product_id,即p.productid=…,不是吗?@tomaspatircak是的,很好!在我的答案中添加了bp前缀。谢谢!太快了!我觉得订单无关紧要。谢谢,那也很有用。谢谢,那也很有用。谢谢,那也很有用。谢谢,那也很有用。谢谢,那也很有用。