News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

How read BoardName from Sub Board Name

Started by dodos26, April 19, 2021, 06:03:49 PM

Previous topic - Next topic

dodos26

How read BoardName from Sub Board Name.

And carefully browsing the topic, I can get information about the category in which the post is located, I can get information about the "BoardName" section (but it is the BoardName in which the topic is located, i.e. the name of the board). I would like to get all three items at once for a category, BoardName and subBoardName of the topic it is in.

I am an amateur and I wish that this could be put into a database query. Or add some extra routine that will write this in addition to the row.
If there was a need for an additional function to enter this data into the table.
This could be added with a change, thanks to which I will be able to check whether the topic is in the subboard or the regular board.

global $smcFunc, $scripturl, $modSettings, $user_info, $txt, $context, $color_profile, $settings, $db_prefix;

$list_limit = 10;
$display_type = 'full';

$request = $smcFunc['db_query']('', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
WHERE t.id_board != 0' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' : '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}',
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);

dodos26


dodos26

Hey I add " b.id_parent in
$request = $smcFunc['db_query']('', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.id_parent, b.name AS board_name, t.num_replies, t.num_views,
' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' : '') . '
WHERE t.id_board != 0' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' : '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}',
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);
"

and try read
foreach ($topics as $item)
{
$test = array();
$test[] = getBoardParents($item['id_parent']);
....
[' . $test['board_name'] .']
....}

but i dont see when try read. In fact, I have come to this myself to analyze function loadBoard() how getBoardParents work??

Me full code:
<?php
{

global $smcFunc, $scripturl, $modSettings, $user_info, $txt, $context, $color_profile, $settings, $db_prefix;

$list_limit = 10;
$display_type = 'full';

$request = $smcFunc['db_query']('', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.id_parent, b.name AS board_name, t.num_replies, t.num_views,
'
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)'
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})'
: '') . '
WHERE t.id_board != 0'
. ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}'
: '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}'
,
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);


if (empty($topics))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$topics[count($topics) - 1]['is_last'] = true;


$colorids = array();
foreach ($topics as $item)
$colorids[] = $item['id_member'];
sp_loadColors($colorids);


if ($display_type == 'compact')
{
foreach ($topics as $key => $item)
echo '<a href="', $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $color_profile[$item['id_member']]['link'], !empty($item['is_read']) ? '' : ' <a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>','<br />[', timeformat($item['poster_time']), ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display_type == 'full')
{
echo '<table class="sp_fullwidth">';

foreach ($topics as $item)
{
$takazmiennadlazabawy = array();
$takazmiennadlazabawy[] = getBoardParents($item['id_parent']);

echo '
<tr>
<td class="sp_recent_icon sp_center">
'
, sp_embed_image(empty($display_type) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="'
, $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a>
'
, !empty($item['is_read']) ? '' : '<a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', '<a href="' . $scripturl . '?board=' . $item['id_board'] . '.0">' . $item['board_name'] . '</a>', '] [' . $takazmiennadlazabawy['board_name'] .']
</td>
<td class="sp_recent_info sp_right">
'
, $color_profile[$item['id_member']]['link'], ' | ', $txt['sp-articlesViews'], ': ', $item['num_views'], ' | ', $txt['sp-articlesComments'], ': ', $item['num_replies'], '<br />', timeformat($item['poster_time']), '
</td>
</tr>'
;
}
echo '</table>';
}


}
?>

shadav

I guess I'm not understand what it is that you are trying to do

you want the full path to be displayed on the page?

It already does that
Site Name > forum (not sure why that's there) > Category Name > Board Name > Topic Title

Site Name > forum (not sure why that's there) > Category Name > Main Board Name > Sub Board Name > Topic Title

Site Name > forum (not sure why that's there) > Category Name > Main Board Name > Sub Board Name > Sub Sub Board Name > Topic Title

dodos26

I'm trying to understand it

foreach ($topics as $item)
{
$takazmiennadlazabawy = array();
$takazmiennadlazabawy[] = getBoardParents($item['id_parent']);
foreach ($takazmiennadlazabawy as $key1 => $hitem) {
//echo 'START' . $key1 . 'END';
foreach ($hitem as $key2 => $dipem) {
//echo 'START' . $key2 . 'END';
foreach ($dipem as $key3 => $sitem) {
//echo 'START' . $key3 . 'END';
echo $sitem['name'];
foreach ($sitem as $key4 => $uitem) {
echo 'START' . $key4 . 'END';
echo $uitem;
}
}
}
}


I found out that there is an array name "name" "url" "level" "moderator"  But when I want to display using sitem['name'] two letters and a number, when I do not give the key it displays all the keys. I am an amateur and I do it based on php wiki and analysis

dodos26

Quote from: shadav on April 20, 2021, 06:46:19 PM
I guess I'm not understand what it is that you are trying to do

you want the full path to be displayed on the page?

It already does that
Site Name > forum (not sure why that's there) > Category Name > Board Name > Topic Title

Site Name > forum (not sure why that's there) > Category Name > Main Board Name > Sub Board Name > Topic Title

Site Name > forum (not sure why that's there) > Category Name > Main Board Name > Sub Board Name > Sub Sub Board Name > Topic Title


My script lists the latest topics, but many of the topics are on the sub-boards.  When I use the senses from the board_name database, the name sub_board is displayed.
i want to learn how to read the name of the main board name.

Topic is in "Category Name > Main Board Name > Sub Board Name"
When db query to read post information i can read "Sub Board Name" but dont know how read "Main Board Name".


How add this attchament function to me procedure:
<?php
{

global $smcFunc, $scripturl, $modSettings, $user_info, $txt, $context, $color_profile, $settings, $db_prefix;

$list_limit = 10;
$display_type = 'full';

$request = $smcFunc['db_query']('', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
'
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)'
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})'
: '') . '
WHERE t.id_board != 0'
. ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}'
: '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}'
,
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);


if (empty($topics))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$topics[count($topics) - 1]['is_last'] = true;


$colorids = array();
foreach ($topics as $item)
$colorids[] = $item['id_member'];
sp_loadColors($colorids);


if ($display_type == 'compact')
{
foreach ($topics as $key => $item)
echo '<a href="', $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $color_profile[$item['id_member']]['link'], !empty($item['is_read']) ? '' : ' <a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>','<br />[', timeformat($item['poster_time']), ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display_type == 'full')
{
echo '<table class="sp_fullwidth">';

foreach ($topics as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
'
, sp_embed_image(empty($display_type) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="'
, $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a>
'
, !empty($item['is_read']) ? '' : '<a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', '<a href="' . $scripturl . '?board=' . $item['id_board'] . '.0">' . $item['board_name'] . '</a>', ']
</td>
<td class="sp_recent_info sp_right">
'
, $color_profile[$item['id_member']]['link'], ' | ', $txt['sp-articlesViews'], ': ', $item['num_views'], ' | ', $txt['sp-articlesComments'], ': ', $item['num_replies'], '<br />', timeformat($item['poster_time']), '
</td>
</tr>'
;

echo '</table>';
}


}
?>

dodos26

okay i managed to do this in case someone needed some code for design in the future
<?php
{

global $smcFunc, $scripturl, $modSettings, $user_info, $txt, $context, $color_profile, $settings, $db_prefix;

$list_limit = 10;
$display_type = 'full';

$request = $smcFunc['db_query']('', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.id_parent, b.name AS board_name, t.num_replies, t.num_views,
'
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)'
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})'
: '') . '
WHERE t.id_board != 0'
. ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}'
: '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}'
,
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);


if (empty($topics))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$topics[count($topics) - 1]['is_last'] = true;


$colorids = array();
foreach ($topics as $item)
$colorids[] = $item['id_member'];
sp_loadColors($colorids);


if ($display_type == 'compact')
{
foreach ($topics as $key => $item)
echo '<a href="', $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $color_profile[$item['id_member']]['link'], !empty($item['is_read']) ? '' : ' <a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>','<br />[', timeformat($item['poster_time']), ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display_type == 'full')
{
echo '<table class="sp_fullwidth">';

foreach ($topics as $item)
{
$allOfParents = array();
$allOfParents = array_reverse(getBoardParents($item['id_parent']));

echo '
<tr>
<td class="sp_recent_icon sp_center">
'
, sp_embed_image(empty($display_type) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="'
, $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['id_msg'] . ';topicseen#new', '">', $item['subject'], '</a>
'
, !empty($item['is_read']) ? '' : '<a href="' . $scripturl . '?topic=' . $item['id_topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>',
'<br />';
foreach ($allOfParents as $link_num => $Parents_Data)
{
echo isset($Parents_Data['url']) ? '[<a href="' . $Parents_Data['url'] . '">' . $Parents_Data['name'] . '</a>]' : '[' . $Parents_Data['name'] . ']';
echo ' &#38;#187; ';
}
echo '[', '<a href="' . $scripturl . '?board=' . $item['id_board'] . '.0">' . $item['board_name'] . '</a>', ']
</td>
<td class="sp_recent_info sp_right">
'
, $color_profile[$item['id_member']]['link'], ' | ', $txt['sp-articlesViews'], ': ', $item['num_views'], ' | ', $txt['sp-articlesComments'], ': ', $item['num_replies'], '<br />', timeformat($item['poster_time']), '
</td>
</tr>'
;
}
echo '</table>';
}

}
?>

Advertisement: