MyBB Hacks

Full Version: Last poster avatar in forumlist
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying put last poster avatar in forumlist, but i donĀ“t want increase query.

So i make modification in index.php

PHP Code:
if($mybb->user['uid'] == 0)
{
	// Build a forum cache.
	$query = $db->query("
		SELECT *
		FROM ".TABLE_PREFIX."forums
		WHERE active != 0
		ORDER BY pid, disporder
	");
	
	$forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
}
else
{
	// Build a forum cache.
	$query = $db->query("
		SELECT f.*, fr.dateline AS lastread
		FROM ".TABLE_PREFIX."forums f
		LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
		WHERE f.active != 0
		ORDER BY pid, disporder
	");
}


to

PHP Code:
if($mybb->user['uid'] == 0)
{
	// Build a forum cache.
	$query = $db->query("
		SELECT *, f.*,  lp.avatar
		FROM ".TABLE_PREFIX."forums f
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=f.lastposteruid)
		WHERE active != 0
		ORDER BY pid, disporder
	");
	
	$forumsread = my_unserialize($mybb->cookies['mybb']['forumread']);
}
else
{
	// Build a forum cache.
	$query = $db->query("
		SELECT f.*, fr.dateline AS lastread, lp.avatar
		FROM ".TABLE_PREFIX."forums f
		LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
		LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=f.lastposteruid)
		WHERE f.active != 0
		ORDER BY pid, disporder
	");
}


But I do not know if these changes will cause some problem in the functionality of the forum.

especially in this modification

FROM ".TABLE_PREFIX."forums to FROM ".TABLE_PREFIX."forums f

thanks....

That part should be fine, though I recommend prefixing all other fields with "f.", eg "f.pid", "f.disporder".
Just be aware that "SELECT *, f.*" is ambiguous - you may wish to remove the first *

That won't really harm your forum anyway, so just try it out on a test board (or if you're lazy like me, just chuck it up on your live board and fix it up if you get an SQL error).
(06-13-2012 11:10 PM)ZiNgA BuRgA Wrote: [ -> ]That part should be fine, though I recommend prefixing all other fields with "f.", eg "f.pid", "f.disporder".
Just be aware that "SELECT *, f.*" is ambiguous - you may wish to remove the first *

That won't really harm your forum anyway, so just try it out on a test board (or if you're lazy like me, just chuck it up on your live board and fix it up if you get an SQL error).

thanks reply...
this code i tested locally and work fine...

but as I did not know what could cause problems by modifying FROM ".TABLE_PREFIX."forums to FROM ".TABLE_PREFIX."forums f, so I decided to ask.

PHP Code:
$query = $db->query("
		SELECT *
		FROM ".TABLE_PREFIX."forums
		WHERE active != 0
		ORDER BY pid, disporder
	");

to

PHP Code:
$query = $db->query("
		SELECT f.*,  lp.avatar
		FROM ".TABLE_PREFIX."forums f
                LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=f.lastposteruid)
		WHERE active != 0
		ORDER BY pid, disporder
	");


thanks again...

Reference URL's