2011-10-10 72 views
0

我對PHP下面的代碼'where子句中的未知列?

 $query = sprintf("SELECT to_go.to_location FROM to_go 
       INNER JOIN to_location ON to_go.to_location_id = to_location.id 
        WHERE match(to_location) against(%s)", mysql_real_escape_string($location)); 

我想盡一切事情,但它保持輸出我下面的錯誤「在「未知列where子句?」我試圖改變列的名稱,仍然同樣的問題

+0

硬而不表來判斷。一種測試方法是編寫sql並替換變量等,然後在sql命令行或mysql查詢工具中運行它。你將會得到更好的診斷和更好的錯誤可視性 – PurplePilot

回答

0

我猜你可能需要更換

WHERE match(to_location) 

WHERE match(to_go.to_location) 
0

既然你有一個列名相同的名稱一個表名,MySql可能會讓他們感到困惑,並且認爲match(to_location)引用了表。嘗試使用完全限定的列名稱,即table_name.column_name

2

match(to_location) against需要提供一個字段,而不是一個表:

match(to_location.id) against(something)