MyBB Community Forums

Full Version: Sort in Memberlist
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, ZiNga BuRgA created a topics started (threads started) column on the member list for me but I can't sort by that column because I don't know the code.

Here's the original:
<option value="regdate"{$regdatesel}>{$lang->sort_regdate}</option>
<option value="username"{$usernamesel}>{$lang->sort_username}</option>
<option value="postnum"{$postnumsel}>{$lang->sort_posts}</option>

I've tried to find where mybb stores the variables needed for these sort options but can't find where to start. I've been able to add the option for search by topic by adding this is the dropdown box at the bottom of the member list page:

<option value="regdate"{$regdatesel}>{$lang->sort_regdate}</option>
<option value="username"{$usernamesel}>{$lang->sort_username}</option>
<option value="postnum"{$postnumsel}>{$lang->sort_posts}</option>
<option value="numtopics"{$users['numtopics']}>Topics</option>

Can someone point me in the direction of where to find the database query's or the variables from these querys?
still needing help
I think that if we edit this section in the memberlist.php file...

Line 88 starts the if statements:
if($mybb->input['by'] == "postnum")

What if we added the variable we want:
elseif($mybb->input['by'] == "numtopics")
{
	$numtopicssel = " selected=\"selected\"";
}


The memberlist template should be added like:
<option value="numtopics"{$numtopicssel}>{$lang->sort_topics}</option>

In memberlist.lang.php we added:
$l['sort_topics'] = "topics";

All of this adds the topics to the dropdown list. It still doesn't search

and list them on the memberlist page though.

Further on in he memberlist.php page it has the DB queries:

if($mybb->input['usersearch'])
{
	$query = $db->query("
		SELECT u.*, f.*
		FROM ".TABLE_PREFIX."users u
		LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
		WHERE u.username LIKE '%".$db->escape_string($mybb->input

['usersearch'])."%'
		ORDER BY u.".$mybb->input['by']." ".$mybb->input['order']."
		LIMIT $start, ".$mybb->settings['membersperpage']
	);
}
else
{
	$query = $db->query("
		SELECT u.*, f.*
		FROM ".TABLE_PREFIX."users u
		LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
		ORDER BY u.".$mybb->input['by']." ".$mybb->input['order']."
		LIMIT $start, ".$mybb->settings['membersperpage']
	);
}

My SQL is a bit rusty and it looks like the second query should pick up on my search choices... is this assumption correct? If it is, it's still not working and I'm wondering where I went wrong.
In memberlist.php,
Find:
if($mybb->input['by'] != "regdate" && $mybb->input['by'] != "postnum" && $mybb->input['by'] != "username")
Replace with:
if($mybb->input['by'] != "regdate" && $mybb->input['by'] != "postnum" && $mybb->input['by'] != "username" && $mybb->input['by'] != "numtopics")

Untested, but I think that's all.
Thank you very much ZiNga, that worked like a charm.
If not for your help on everything since i switched to mybb.. i would be lost.

You are indeed a true asset to this mybb community Smile

Allan