решено Помогите с новым запросом r579 viewtopic.php

Dr_Brown

Пользователь
Было выведена категория в топике в пагинации:


Код:
// Get forum/topic data
if ($topic_id)
{
    $sql = "SELECT t.*, f.*, c.cat_title
FROM ". BB_TOPICS ." t, ". BB_FORUMS ." f, ". BB_CATEGORIES ." c
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
AND c.cat_id = f.cat_id
LIMIT 1";
}
elseif ($post_id)
{
    $sql = "SELECT t.*, f.*, p.post_time, c.cat_title
FROM ". BB_TOPICS ." t, ". BB_FORUMS ." f, ". BB_POSTS ." p, ". BB_CATEGORIES ." c
WHERE p.post_id = $post_id
AND t.topic_id = p.topic_id
AND f.forum_id = t.forum_id
AND c.cat_id = f.cat_id
LIMIT 1";
}

По ревизии стало так:
Код:
// Get forum/topic data
if ($topic_id)
{
        $sql = "SELECT t.*, f.*, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f USING(forum_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE t.topic_id = $topic_id
        ";
}
elseif ($post_id)
{
        $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f  USING(forum_id)
                LEFT JOIN ". BB_POSTS        ." p  USING(topic_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE p.post_id = $post_id
        ";
}


Как в новый запрос c.cat_title прикрутить из BB_CATEGORIES ?
 

krumax

Пользователь
PHP:
        $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f  USING(forum_id)
                LEFT JOIN ". BB_POSTS        ." p  USING(topic_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE p.post_id = $post_id
        ";

вот как-то так должно быть у тебя

PHP:
        $sql = "SELECT t.*, f.*, p.post_time, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f  USING(forum_id)
                LEFT JOIN ". BB_CATEGORIES  ."  c   ON(c.cat_id = f.cat_id)
                LEFT JOIN ". BB_POSTS        ." p  USING(topic_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE p.post_id = $post_id
        ";
 

Dr_Brown

Пользователь
krumax, спс, отработало.....правильный запрос, кто выводил категорию в топике:

PHP:
if ($topic_id)
{
        $sql = "SELECT t.*, f.*, c.cat_title, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f USING(forum_id)
                LEFT JOIN ". BB_CATEGORIES  ." c ON(c.cat_id = f.cat_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE t.topic_id = $topic_id
        ";
}
elseif ($post_id)
{
        $sql = "SELECT t.*, f.*, c.cat_title, p.post_time, tw.notify_status
                FROM ". BB_TOPICS            ." t
                LEFT JOIN ". BB_FORUMS      ." f  USING(forum_id)
                LEFT JOIN ". BB_CATEGORIES  ." c  ON(c.cat_id = f.cat_id)
                LEFT JOIN ". BB_POSTS        ." p  USING(topic_id)
                LEFT JOIN ". BB_TOPICS_WATCH ." tw ON(tw.topic_id = t.topic_id AND user_id = {$userdata['user_id']})
                WHERE p.post_id = $post_id
        ";
}
 

Phoenix

Пользователь
Dr_Brown, Вывод категории для форума и топика, можно сделать иначе, не прибегая к изменению запросов.
Ниже полная установка:

Открыть viewforum.php
найти:
PHP:
// Subforums
$show_subforums = ($bb_cfg['sf_on_first_page_only']) ? !$start : true;
 
if (!$forums = $datastore->get('cat_forums'))
{
    $datastore->update('cat_forums');
    $forums = $datastore->get('cat_forums');
}
добавить после:
PHP:
$template->assign_vars(array(
    'CAT_NAME'   => $forums['cat_title_html'][$forum_data['cat_id']],
    'U_VIEW_CAT' => CAT_URL . $forum_data['cat_id'],
));
Открыть viewtopic.php
найти:
PHP:
if ($parent_id = $t_data['forum_parent'])
{
    if (!$forums = $datastore->get('cat_forums'))
    {
        $datastore->update('cat_forums');
        $forums = $datastore->get('cat_forums');
    }
 
    $template->assign_vars(array(
        'HAS_PARENT_FORUM'  => true,
        'PARENT_FORUM_HREF' => FORUM_URL . $parent_id,
        'PARENT_FORUM_NAME' => htmlCHR($forums['f'][$parent_id]['forum_name']),
    ));
    unset($forums);
}
$datastore->rm('cat_forums');
заменить на:
PHP:
if (!$forums = $datastore->get('cat_forums'))
{
    $datastore->update('cat_forums');
    $forums = $datastore->get('cat_forums');
}
 
$template->assign_vars(array(
    'CAT_NAME'   => $forums['cat_title_html'][$t_data['cat_id']],
    'U_VIEW_CAT' => CAT_URL . $t_data['cat_id'],
));
 
if ($parent_id = $t_data['forum_parent'])
{
    $template->assign_vars(array(
        'HAS_PARENT_FORUM'  => true,
        'PARENT_FORUM_HREF' => FORUM_URL . $parent_id,
        'PARENT_FORUM_NAME' => htmlCHR($forums['f'][$parent_id]['forum_name']),
    ));
}
unset($forums);
$datastore->rm('cat_forums');
Открыть templates\default\viewforum.tpl и templates\default\viewtopic.tpl
найти в обоих файлах дважды встречающиеся совпадения:
PHP:
<a href="{U_INDEX}">{T_INDEX}</a>
ниже добавить (также после каждого совпадения в каждом файле):
PHP:
<em>&raquo;</em>&nbsp;<a href="{U_VIEW_CAT}">{CAT_NAME}</a>
 
Сверху