curlコマンドで自分で作ったAPIのデータを取得しようとしたところ次のようなエラーがでて落ち込む。
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN price AS p ON h.id = p.hotel_id
WHERE
p.target_date = '20190205'
' at line 9"
ただ読んでみると、意外と簡単に解決できそうで要は
「オメ--SQLの書き方間違ってんだよ!」
ということで調べてみると
$sql = "
SELECT
p.target_date,
h.name,
h.area,
p.min_price,
h.link
FROM
hotel AS h
INNER JOIN price AS p ON h.id = p.hotel_id
WHERE
p.target_date = ?
AND h.place = ?
";
if (!empty($condition["order"]) && ($condition["order"] == "high")) {
$sql .= " ORDER BY p.max_price DESC ";
} elseif (!empty($condition["order"]) && ($condition["order"] == "low")) {
$sql .= " ORDER BY p.min_price ASC ";
}
if (!empty($condition["list"]) && ($condition["list"] <= 20) && (is_numeric($condition["list"]))) {
$sql .= " LIMIT " . $condition["list"];
} else {
$sql .= " LIMIT 20 ";
}
このSQL文の
$sql .= " ORDER BY p.max_price DESC ";
ORDERの前に空白が入っていないのが問題でした(上は修正後)
皆さんも空白忘れやカンマ忘れに気をつけましょう。