Last poster avatar in forumlist
martec Offline
Junior Member
**
Posts: 3
Joined: Jun 2012
Post: #1
Last poster avatar in forumlist
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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....

06-13-2012 10:43 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Last poster avatar in forumlist
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).

My Blog
06-13-2012 11:10 PM
Find all posts by this user Quote this message in a reply
martec Offline
Junior Member
**
Posts: 3
Joined: Jun 2012
Post: #3
RE: Last poster avatar in forumlist
(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:
1
2
3
4
5
6
$query = $db->query("
		SELECT *
		FROM ".TABLE_PREFIX."forums
		WHERE active != 0
		ORDER BY pid, disporder
	");

to

PHP Code:
1
2
3
4
5
6
7
$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...

(This post was last modified: 06-14-2012 07:18 AM by martec.)
06-14-2012 07:04 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: