我有一個SQL查詢的問題。這是原來的功能:PHP:爲什麼我不能在這個SQL查詢中使用WHERE?
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' –
感謝您的後也會搖擺。 –