fixed sql error.

This commit is contained in:
CBS Information System 2020-12-17 17:31:06 +09:00
parent 7d256444b3
commit 5951f34dd0

View File

@ -431,6 +431,7 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count
} }
} }
$columns = ['topics', 'forumid', 'first_postid', 'userid', 'title', 'slug', 'created', 'modified', 'last_post', 'posts', 'votes', 'answers', 'views', 'meta_key', 'meta_desc', 'type', 'solved', 'closed', 'has_attach', 'private', 'status', 'name', 'email', 'prefix', 'tags'];
$sql = 'SELECT `'.WPF()->tables->topics.'`.* FROM `'.WPF()->tables->topics.'`'; $sql = 'SELECT `'.WPF()->tables->topics.'`.* FROM `'.WPF()->tables->topics.'`';
if (!is_null($join)) { if (!is_null($join)) {
$sql .= $join; $sql .= $join;
@ -442,9 +443,8 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count
$item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql); $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
if ($item_count_sql) { if ($item_count_sql) {
if (!is_null($join)) { if (!is_null($join)) {
$keys = ['topics', 'forumid', 'first_postid', 'userid', 'title', 'slug', 'created', 'modified', 'last_post', 'posts', 'votes', 'answers', 'views', 'meta_key', 'meta_desc', 'type', 'solved', 'closed', 'has_attach', 'private', 'status', 'name', 'email', 'prefix', 'tags']; foreach ($columns as $column) {
foreach ($keys as $key) { $item_count_sql = preg_replace('/([( ])`'.$column.'`/', '\1`'.WPF()->tables->topics.'`.`'.$column.'`', $item_count_sql);
$item_count_sql = str_replace(' `'.$key.'`', ' `'.WPF()->tables->topics.'`.`'.$key.'`', $item_count_sql);
} }
} }
$items_count = WPF()->db->get_var($item_count_sql); $items_count = WPF()->db->get_var($item_count_sql);
@ -462,9 +462,8 @@ function cbsonline_wpforo_topic_get_topics($args = [], &$items_count = 0, $count
} }
if (!is_null($join)) { if (!is_null($join)) {
$keys = ['topics', 'forumid', 'first_postid', 'userid', 'title', 'slug', 'created', 'modified', 'last_post', 'posts', 'votes', 'answers', 'views', 'meta_key', 'meta_desc', 'type', 'solved', 'closed', 'has_attach', 'private', 'status', 'name', 'email', 'prefix', 'tags']; foreach ($columns as $column) {
foreach ($keys as $key) { $sql = preg_replace('/([( ])`'.$column.'`/', '\1`'.WPF()->tables->topics.'`.`'.$column.'`', $sql);
$sql = str_replace(' `'.$key.'`', ' `'.WPF()->tables->topics.'`.`'.$key.'`', $sql);
} }
} }