Need help to edit some code

Dylert,

Thanks for being a sport and re-posting the code each time, It’s like coding in the dark without being able to test the results.

Change:

[php] ‘name’ => !empty($row_topics[‘name’]),
‘topic_member’ => !empty($row_topics[‘topic_member’])[/php]

To:

[php] ‘name’ => $row_topics[‘name’],
‘topic_member’ => $row_topics[‘topic_member’][/php]

WOW! :slight_smile: :smiley: It works! :wink: It’s so great! Thank you very, very much!

Only one small thing if you have time: In “Topic starter” there’s no link to the topic starter, and in “Board name” there’s no link to the board…

Just wrap it all up in A tags

Similar to what you have coded here…

[php] ‘poster’ => ‘’ . $row_topics[‘poster_name’] . ‘’,[/php]

For example on the the topic member you’re going to need to pull back the member id also…

Change:

[php] 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,
[/php]
To:

[php] SELECT z.member_name as topic_member, t.id_member_started, 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, [/php]

Then Change…

[php]‘topic_member’ => $row_topics[‘topic_member’][/php]

To:

[php]‘topic_member’ => ‘’ . $row_topics[‘topic_member’]. ‘’,
[/php]

Then do the same thing for the board name…

Thanks, Topcoder! :slight_smile: Link to the topic starter went well, but I’m struggling with link to board. :frowning:

Links to the boards finally went well! :slight_smile: :slight_smile:

'name' =>  '<a style="color: ' . ';" href="' . $scripturl . '?board=' . $row_topics['id_board'] . '">' . $row_topics['name'] . '</a>',

Awesome, doesn’t it feel good to do it on your own :slight_smile:

Also do you mind sharing a link to your board, so I can see how it looks.

Once again: Thanks a lot, Topcoder! :slight_smile:

It feels really good to see it works. In fact I don’t know anything about coding, but I try to see what makes sense and then try. Sometimes it works.

I will put the code in a tabbed block and each tab will show recent posts from a spesific board. I hope to finish the work tonight. My site is http://www.hellasforum.net

I will tell you when I’m finished.

So it’s not live yet…

Let me know when you’re done… :slight_smile:

The block is now up on http://hellasforum.net/ It’s on the bottom of the page.

And here’s the final code (including Views/posts):

[code]$num_recent = 40; // 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, t.id_member_started, m.poster_name, m.poster_time, m.id_msg, t.num_replies, t.num_views, 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)
INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)
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’]),
‘views_replies’ => $row_topics[‘num_views’] . ‘/’ . $row_topics[‘num_replies’],

     	  'name' =>  '<a style="color: ' . ';" href="' . $scripturl . '?board=' . $row_topics['id_board'] . '">' . $row_topics['name'] . '</a>',
	  
  'topic_member' => '<a style="color: ' . ';" href="' . $scripturl . '?action=profile;u=' . $row_topics['id_member_started'] . '">' . $row_topics['topic_member']. '</a>',
);

}
$smcFunc’db_free_result’;
echo ’









			<td valign="middle"></td>
		</tr>';

foreach ($topics as $topic)
{
	echo '
		<tr>
			
			<td class="windowbg" valign="middle">', str_replace('Sv:' , '' , $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">';
	
	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 By Topic starter Views/posts Board Time ', $topic['poster'], ' ', $topic['topic_member'], ' ', $topic['views_replies'], ' ', $topic['name'], ' ', $topic['time'], '

'; [/code]

Looks good, wish I knew how to speak multiple languages as you!

I had no idea that’s what it was going to look like, I had something completely different in mind.

I also post as “PHPHelp”, I try to post as my user id. I use on all forums, but sometimes I get mixed up and post as “PHPHelp” and “TopCoder”, I’m sure I confuse a lot of people.

You should post the code solution on the SMF Forums under the topic you started, so someone else can benefit from it.

I started a new topic in the SMF forum as a tip on how to do it. Hopefully someone can use it: http://www.simplemachines.org/community/index.php?topic=514950.0

Can I ask one more question? :slight_smile:

If you’re concerned about with the SMF person said…

You can change the inner join statement…

Change:
[php]INNER JOIN smf_members AS z ON (t.id_member_started = z.id_member)[/php]

To:
[php]LEFT JOIN smf_members AS z ON (t.id_member_started = z.id_member)[/php]

Ok, I will change the inner join statement. Thanks!

I try… And I have tried for some hours, but with no luck to make even and odd rows with different colors. The table would have been much easier to read. Any suggestions?

Just like this:

:smiley: :smiley: Found a solution! :slight_smile:

Added this code to my index.css

#table_box { width:100%; font-size: 12px; border-collapse: collapse; text-align:left; } #table_box th { padding:7px; color: #292929; } #table_box td { padding: 4px 0 4px 0; color: #464646; } #table_box tr { border-bottom:1px solid #cecece; } #table_box tr:nth-child(odd) td { background-color:#ffffff } /*odd*/ #table_box tr:nth-child(even) td { background-color:#f5f9fa } /* even*/ #table_box tr:hover td { background-color:#fffbae; } /* hovering */ }

Changed this line:

<table border="0" width="100%" cellspacing="1" cellpadding="2" class="bordercolor">

To this:

<table id="table_box" border="0" width="100%" cellspacing="1" cellpadding="2" class="bordercolor">

It makes different colors on odd and even rows, and a hover effect. I will put it om my site soon. :slight_smile:

Glad you got it working!

Sponsor our Newsletter | Privacy Policy | Terms of Service