カテゴリー:
エラー
閲覧数:301 配信日:2017-10-29 11:29
エラー対応
修正前
public function fetchByParentCategoryid2new($category_id)
{
$sql = "
SELECT
a.id AS id,
a.category_id AS category_id,
a.state_id AS state_id,
a.counter AS counter,
a.created_at AS created_at,
a.modified AS modified,
a.body AS body,
topic_name,
r.modified AS rmodified,
r.body AS rbody,
u.display_name, u.site_id, c.category, c.parent_id,s.situation, s.fonticon,s.color,relationentrynum
FROM
status AS a
LEFT JOIN user u ON a.user_id = u.id
LEFT JOIN category c ON a.category_id = c.category_id
LEFT JOIN state s ON a.state_id = s.state_id
LEFT OUTER JOIN(
SELECT
topic_id,`body`, MAX(modified) AS modified, COUNT(topic_id) AS `relationentrynum`
FROM
res
GROUP BY topic_id
) AS r ON a.id = r.topic_id";
$where = array();
$bind = array();
foreach ($category_id as $val) {
$where[] = 'a.`category_id` = ? ';//単一キーワード
$bind[] = '' . $val . '';
}
$sql .= ' where ' . implode('or ', $where);
$sql .= ' and public = 1 ';
$sql .= 'ORDER BY a.created_at ASC';
return $this->fetchAll($sql, $bind);
}
修正後
ANY_VALUE(`body`)
public function fetchByParentCategoryid2new($category_id)
{
$sql = "
SELECT
a.id AS id,
a.category_id AS category_id,
a.state_id AS state_id,
a.counter AS counter,
a.created_at AS created_at,
a.modified AS modified,
a.body AS body,
topic_name,
r.modified AS rmodified,
r.body AS rbody,
u.display_name, u.site_id, c.category, c.parent_id,s.situation, s.fonticon,s.color,relationentrynum
FROM
status AS a
LEFT JOIN user u ON a.user_id = u.id
LEFT JOIN category c ON a.category_id = c.category_id
LEFT JOIN state s ON a.state_id = s.state_id
LEFT OUTER JOIN(
SELECT
topic_id,ANY_VALUE(`body`) AS body, MAX(modified) AS modified, COUNT(topic_id) AS `relationentrynum`
FROM
res
GROUP BY topic_id
) AS r ON a.id = r.topic_id";
$where = array();
$bind = array();
foreach ($category_id as $val) {
$where[] = 'a.`category_id` = ? ';//単一キーワード
$bind[] = '' . $val . '';
}
$sql .= ' where ' . implode('or ', $where);
$sql .= ' and public = 1 ';
$sql .= 'ORDER BY a.created_at ASC';
return $this->fetchAll($sql, $bind);
}
・セッション系のSQLでエラーが発生。仕組みだけ作成して、クッキー設定していなかったから?