我有一個問題:(SQL函數(加入)的REST API PHP,probleme
我有三個表:
表書
- ID
- 標題
- id_author
表筆者
- ID
- 名
- ID_TYPE
表型
- ID
- nameOfType
我想在參數「id_author」和可選參數「id_type」中獲得我的書籍。 例如,如果我過濾所有類型的書籍。
我嘗試:
public function get_books($id_author, $id_type = null)
{
if ($id_author == 0 && $id_type){
$books= \DB::query("SELECT DISTINCT id, title FROM book LEFT JOIN book ON author.id LEFT JOIN author ON type.id")->execute();
} elseif ($id_author) {
$books= \DB::query("SELECT distinct id, title FROM book WHERE id_author=" .$id_author." ORDRE BY id") -> execute();
}
}
但沒有奏效....
任何人都可以幫我嗎? :)
沒有工作意味着什麼? –
你必須指定兩個連接列。例如。 「ON author.id = book.author_id」 – jarlh