Need help to edit some code

Hello!I have a block code to my SMF forum. The block shows a table with recent topics. The problem is that it shows only name of topic, poster and date. I would like to add topic starter and board name (and maybe (views/read). Can anyone help me with this? :slight_smile:

The code:

[code]$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

// code, code, code and some more code bahhh!
global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;

if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
	$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
	$output_method = $include_boards;
	$include_boards = array();
}

$topics_result = $smcFunc[‘db_query’](’’, ’
SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($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}boards AS b ON (t.id_board = b.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)’ . (!$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 m.approved=1’ . (empty($include_boards) ? ‘’ : ’
AND b.id_board IN ({array_int:include_boards})’) . ’
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
);
}
$smcFunc’db_free_result’;
echo ’








';
foreach ($topics as $topic)
{
	echo '
		<tr>
			<td class="windowbg" valign="middle">', $topic['link'];
	
	// new log! What a headache!
	if (!$topic['new'] && $context['user']['is_logged'])
		echo '
				<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
			
	echo '
			</td>
			<td class="windowbg2" valign="middle">', $topic['poster'], '</td>
			<td class="windowbg2" valign="middle">', $topic['time'], '</td>
			<td class="windowbg2" valign="middle">';
	
	if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
		echo '
				<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}

echo ’


Topic Poster Time

'; [/code]

Dylert,

Since you’re talking SMF, they have a fantastic community that will answer you question 100% to perfect accuracy. What your asking to happen is something that’s very simple. But instead of giving you a quick and dirty answer. Ask the question over on …

http://www.simplemachines.org/community/index.php

They are extremely helpful and will guide you through the pro’s and con’s of any changes.

I have tried at the SMF community and they want me to use SSI. Maybe it is a good solution, but for me I think the code is best. I will try SSI when I understand that. In the meantime I want to use the code. If you can tell me what to add to the code I’m happy! :slight_smile:

Any chance to get help with this code? :slight_smile:

SSI doesn’t work for me, because it only outputs results from the last 7 days. :frowning:

I didn’t test any of this… Just off the code you posted you should make the following changes…

Change:

[php]

Topic
Poster
Time
[/php]

To:

[php]

Topic
Poster
Time
Topic Starter
Board Name
[/php]

Then

Change:

[php]

’, $topic[‘poster’], ’
', $topic[‘time’], '[/php]

to

[php]

’, $topic[‘poster’], ’ ', $topic['time'], ' ', $topic['time'], ' ', $topic['topic_member'], '

Then you need to change the query…
Change:

[php] SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($user_info[‘is_guest’] ? ‘1 AS is_read, 0 AS new_from’ : '[/php]

To:

[php] SELECT (SELECT member_name FROM phphelp.smf_members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($user_info[‘is_guest’] ? ‘1 AS is_read, 0 AS new_from’ : ’
[/php]

Hmm, it doesn’t work. It outputs the heading of my site…

Is this correct? (including “FROM phphelp”)

[code]SELECT (SELECT member_name FROM phphelp.smf_members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($user_info[‘is_guest’] ? ‘1 AS is_read, 0 AS new_from’ : ’

[/code]

Sorry about that phphelp is the name of my database, anyway just switch it up… to what I have below.

This:

[php]SELECT (SELECT member_name FROM phphelp.smf_members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($user_info[‘is_guest’] ? ‘1 AS is_read, 0 AS new_from’ : '[/php]

Should be:

[php]SELECT (SELECT member_name FROM {db_prefix}members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($user_info[‘is_guest’] ? ‘1 AS is_read, 0 AS new_from’ : '[/php]

Thanks a lot for the help so far! Anyway, the block doesn’t work. Is it possible for you to test the block?

There’s two similar lines. Should it be “board” instead of “time”?

[code]

', $topic[‘poster’], ’ ', $topic['time'], ' ', $topic['time'], ' ', $topic['topic_member'], '</td[/code]

But that’s not the main problem that the block doesn’t work I think.

Heres’s my code now:

[code]$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

// code, code, code and some more code bahhh!
global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;

if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
	$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
	$output_method = $include_boards;
	$include_boards = array();
}

$topics_result = $smcFunc[‘db_query’](’’, ’
SELECT (SELECT member_name FROM {db_prefix}members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($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}boards AS b ON (t.id_board = b.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)’ . (!$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 m.approved=1’ . (empty($include_boards) ? ‘’ : ’
AND b.id_board IN ({array_int:include_boards})’) . ’
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
);
}
$smcFunc’db_free_result’;
echo ’










';
foreach ($topics as $topic)
{
	echo '
		<tr>
			<td class="windowbg" valign="middle">', $topic['link'];
	
	// new log! What a headache!
	if (!$topic['new'] && $context['user']['is_logged'])
		echo '
				<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
			
	echo '
			</td>
			 <td class="windowbg2" valign="middle">', $topic['poster'], '</td>


Topic Poster Time Topic Starter Board Name
', $topic['time'], ' ', $topic[''], ' ', $topic['topic_member'], ' ';
	if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
		echo '
				<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}

echo ’


';[/code]

It should be name

I’m just full of typo’s

[php]

', $topic[‘poster’], ’ ', $topic['time'], ' ', $topic['name'], ' ', $topic['topic_member'], '</td[/php]

Well, the block still doesn’t work. Is it possible for you to test the code?

Is there an error in this line?

 SELECT (SELECT member_name  FROM {db_prefix}members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '

The whole code:

[code]$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

// code, code, code and some more code bahhh!
global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;

	if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
	$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
	$output_method = $include_boards;
	$include_boards = array();
}

$topics_result = $smcFunc[‘db_query’](’’, ’
SELECT (SELECT member_name FROM {db_prefix}members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, ’ . ($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}boards AS b ON (t.id_board = b.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)’ . (!$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 m.approved=1’ . (empty($include_boards) ? ‘’ : ’
AND b.id_board IN ({array_int:include_boards})’) . ’
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
);
}
$smcFunc’db_free_result’;
echo ’










';
foreach ($topics as $topic)
{
	echo '
		<tr>
			<td class="windowbg" valign="middle">', $topic['link'];
	
	// new log! What a headache!
	if (!$topic['new'] && $context['user']['is_logged'])
		echo '
				<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
			
	echo '
			</td>
			   <td class="windowbg2" valign="middle">', $topic['poster'], '</td>


Topic Poster Time Topic Starter Board Name
', $topic['time'], ' ', $topic['name'], ' ', $topic['topic_member'], ' ';
	if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
		echo '
				<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}

echo ’


';[/code]

I did test the QUERY, that’s whey I had my database info in it earlier :stuck_out_tongue:

If it runs without error, then turn on the logging in you admin panel it will show you all the queries that ran on the page.

Then look for the one we modified. Take that sql statement and run it directly in your database and see what it returns.

If you look on the bottom of this forum, you will see something like X queries ran in X seconds…

I just have the partial debugging on, you can go full bore and see everything.

Now it became even more difficult for me! :slight_smile: In my log I get the error:

Hacking attempt…

SELECT (SELECT member_name FROM smf_members where id_member = t.id_member_started) topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color,
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 smf_topics AS t
INNER JOIN smf_boards AS b ON (t.id_board = b.id_board)
INNER JOIN smf_messages AS m ON (m.id_msg = t.id_last_msg)
LEFT JOIN smf_members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN smf_membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
LEFT JOIN smf_log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = 1)
LEFT JOIN smf_log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = 1)
WHERE m.approved=1
ORDER BY t.id_last_msg DESC
LIMIT 25
Function: eval

OMG, it looks like they have some code to prevent sub selects in the select portion of the query…

You’re going to have to add it as another table join like below…

SELECT z.member_name as topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color,
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 smf_topics AS t
INNER JOIN smf_boards AS b ON (t.id_board = b.id_board)
INNER JOIN smf_messages AS m ON (m.id_msg = t.id_last_msg)
INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)
LEFT JOIN smf_members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN smf_membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
LEFT JOIN smf_log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = 1)
LEFT JOIN smf_log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = 1)
WHERE m.approved=1
ORDER BY t.id_last_msg DESC

Thanks, Topcoder!

With the new code the block works, but the two rows, Topic starter and Board name, have no content. And I don’t get errors in the log.

My code is like this now:

[code] $num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

  // code, code, code and some more code bahhh!
  global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;
  
  	if (is_array($include_boards) || (int) $include_boards === $include_boards)
{
	$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
}
elseif ($include_boards != null)
{
	$output_method = $include_boards;
	$include_boards = array();
}

$topics_result = $smcFunc[‘db_query’](’’, ’
SELECT z.member_name as topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color,
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 smf_topics AS t
INNER JOIN smf_boards AS b ON (t.id_board = b.id_board)
INNER JOIN smf_messages AS m ON (m.id_msg = t.id_last_msg)
INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)
LEFT JOIN smf_members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN smf_membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
LEFT JOIN smf_log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = 1)
LEFT JOIN smf_log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = 1)
WHERE m.approved=1
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
);
}
$smcFunc’db_free_result’;
echo ’










';
foreach ($topics as $topic)
{
	echo '
		<tr>
			<td class="windowbg" valign="middle">', $topic['link'];
	
	// new log! What a headache!
	if (!$topic['new'] && $context['user']['is_logged'])
		echo '
				<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
			
	echo '
			</td>
			   <td class="windowbg2" valign="middle">', $topic['poster'], '</td>
<td class="windowbg2" valign="middle">', $topic['time'], '</td>
<td class="windowbg2" valign="middle">', $topic['name'], '</td>
<td class="windowbg2" valign="middle">', $topic['topic_member'], '</td>
			<td class="windowbg2" valign="middle">';
	
	if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
		echo '
				<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
}

echo ’


Topic Poster Time Topic Starter Board Name

';
[/code]

Make this change…

Change:

[php] $topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
);[/php]

To:

[php] $topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
‘name’ => !empty($row_topics[‘name’])
‘topic_member’ => !empty($row_topics[‘topic_member’])
);[/php]

Thanks a lot for the help! :slight_smile: Sorry to say, but the code doesn’t work. Nothing shows up in the block. :slight_smile:

My code is at the moment:

[code]$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

    // code, code, code and some more code bahhh!
    global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;
    
    	if (is_array($include_boards) || (int) $include_boards === $include_boards)
	{
		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
	}
	elseif ($include_boards != null)
	{
		$output_method = $include_boards;
		$include_boards = array();
	}

$topics_result = $smcFunc['db_query']('', '
   SELECT z.member_name as topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, 

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 smf_topics AS t
INNER JOIN smf_boards AS b ON (t.id_board = b.id_board)
INNER JOIN smf_messages AS m ON (m.id_msg = t.id_last_msg)
INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)
LEFT JOIN smf_members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN smf_membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
LEFT JOIN smf_log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = 1)
LEFT JOIN smf_log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = 1)
WHERE m.approved=1
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
‘name’ => !empty($row_topics[‘name’])
‘topic_member’ => !empty($row_topics[‘topic_member’])
);
}
$smcFunc’db_free_result’;
echo ’










';
	foreach ($topics as $topic)
	{
		echo '
			<tr>
				<td class="windowbg" valign="middle">', $topic['link'];
		
		// new log! What a headache!
		if (!$topic['new'] && $context['user']['is_logged'])
			echo '
					<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
				
		echo '
				</td>
				   <td class="windowbg2" valign="middle">', $topic['poster'], '</td>
 <td class="windowbg2" valign="middle">', $topic['time'], '</td>
 <td class="windowbg2" valign="middle">', $topic['name'], '</td>
 <td class="windowbg2" valign="middle">', $topic['topic_member'], '</td>
				<td class="windowbg2" valign="middle">';
		
		if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
			echo '
					<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
	}

echo '
				</td>
			</tr>
		</table>
	</div>';

[/code]

Topic Poster Time Topic Starter Board Name

If I skip “topic starter” and only add “board name”. Is it easier to make it work then??

My bad, I forgot the comma’s

Change:

[php] $topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’])
‘name’ => !empty($row_topics[‘name’])
‘topic_member’ => !empty($row_topics[‘topic_member’])
);[/php]

To:

[php] $topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’]),
‘name’ => !empty($row_topics[‘name’]),
‘topic_member’ => !empty($row_topics[‘topic_member’])
);[/php]

Ok, code changed. Now the two columns “Topic starter” and “Board name” shows the number “1” in all rows. :slight_smile:

The code now:

[code]$num_recent = 25; // HOW MANY RECENT TOPICS TO OUTPUT?
$include_boards = null; // IF ALL BOARDS null | IF SOME BOARDS array( ID1, ID2, ID3)

      // code, code, code and some more code bahhh!
      global $smcFunc, $scripturl, $context, $settings, $db_prefix, $user_info;
      
      	if (is_array($include_boards) || (int) $include_boards === $include_boards)
 	{
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
 	}
 	elseif ($include_boards != null)
 	{
 		$output_method = $include_boards;
 		$include_boards = array();
 	}
 
 $topics_result = $smcFunc['db_query']('', '
    SELECT z.member_name as topic_member, m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, b.id_board, t.id_last_msg, u.avatar, g.online_color, 

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 smf_topics AS t
INNER JOIN smf_boards AS b ON (t.id_board = b.id_board)
INNER JOIN smf_messages AS m ON (m.id_msg = t.id_last_msg)
INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)
LEFT JOIN smf_members AS u ON (t.id_member_updated = u.id_member)
LEFT JOIN smf_membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
LEFT JOIN smf_log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = 1)
LEFT JOIN smf_log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = 1)
WHERE m.approved=1
ORDER BY t.id_last_msg DESC
LIMIT ’ . $num_recent,
array(
‘current_member’ => $user_info[‘id’],
‘include_boards’ => empty($include_boards) ? ‘’ : $include_boards,
)
);
$topics = array();
while ($row_topics = $smcFunc’db_fetch_assoc’)
{
$topics[] = array(
‘topic’ => $row_topics[‘id_topic’],
‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,
‘link’ => ‘’ . $row_topics[‘subject’] . ‘’,
‘href’ => $scripturl . ‘?topic=’ . $row_topics[‘id_topic’] . ‘.msg’ . $row_topics[‘id_last_msg’] . ‘;topicseen#new’,
‘time’ => timeformat($row_topics[‘poster_time’]),
‘new’ => !empty($row_topics[‘is_read’]),
‘name’ => !empty($row_topics[‘name’]),
‘topic_member’ => !empty($row_topics[‘topic_member’])
);
}
$smcFunc’db_free_result’;
echo ’










';
 	foreach ($topics as $topic)
 	{
 		echo '
 			<tr>
 				<td class="windowbg" valign="middle">', $topic['link'];
 		
 		// new log! What a headache!
 		if (!$topic['new'] && $context['user']['is_logged'])
 			echo '
 					<a href="', $scripturl, '?topic=', $topic['topic'], '.from', $topic['time'], '#new"><img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="new" border="0" /></a>';
 				
 		echo '
 				</td>
 				   <td class="windowbg2" valign="middle">', $topic['poster'], '</td>
  <td class="windowbg2" valign="middle">', $topic['time'], '</td>
  <td class="windowbg2" valign="middle">', $topic['name'], '</td>
  <td class="windowbg2" valign="middle">', $topic['topic_member'], '</td>
 				<td class="windowbg2" valign="middle">';
 		
 		if ($settings['images_url'] != $settings['theme_url'] . '/images' || file_exists($settings['theme_dir'] . '/images/icons/last_post.gif'))
 			echo '
 					<a href="', $topic['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="Last Post" title="Last Post" border="0" style="float: right;" /></a>';
 	}
 
 echo '
 				</td>
 			</tr>
 		</table>
 	</div>';[/code]
Topic Poster Time Topic Starter Board Name
Sponsor our Newsletter | Privacy Policy | Terms of Service