MyBB Community Forums

Full Version: Sort By Ratings Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I installed Sort By Ratings mod and getting the following error:

Code:
Parse error: parse error, unexpected T_ELSEIF in /home/chiefsaab/public_html/com/memberlist.php on line 84

Line number 84 is in red color in the following code of memberlist.php file after adding the mod. MM your help please Sad Will it be possible for you to post the entire modified code of memberlist.php which will work correctly? Thanx Smile

Code:
<?php
/**
* MyBulletinBoard (MyBB)
* Copyright � 2004 MyBulletinBoard Group, All Rights Reserved
*
* Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html
*
*/

$templatelist = "memberlist,memberlist_row";
require "./global.php";

$userpermissions = getuserpermissions($mybb['uid']);
if($userpermissions['canviewmemberlist'] == "no")
{
    nopermission();
}

if($by != "regdate" && $by != "postnum" && $by != "username" && $by != "rating")
{
    if($usersearch)
    {
        $by = "username";
    }
    else
    {
        $by = "regdate";
    }
}

if($order != "DESC" && $order != "ASC")
{
    // top posters first
    if($by == "postnum")
    {
        $order = "DESC";
    }
[color=red]elseif($by == "rating")[/color]
{
    $order = "ASC";
}
    else
    {
        $order = "ASC";
    }
}

if($usersearch)
{
    $query = $db->query("SELECT COUNT(*) FROM users WHERE username LIKE '%$usersearch%'");
    $linkaddon = "&usersearch=$usersearch";
}
else
{
    $query = $db->query("SELECT COUNT(*) FROM users");
    $linkaddon = "";
}

$num = $db->result($query, 0);
$multipage = multipage($num, $settings['membersperpage'], $page, "memberlist.php?by=$by&order=$order$linkaddon");
if($page)
{
    $start = ($page - 1) * $settings['membersperpage'];
}
else
{
    $start = 0;
    $page = 1;
}

if($by == "postnum")
{
    $postnumsel = " selected=\\"selected\\"";
}
elseif($by == "username")
{
    $usernamesel = " selected=\\"selected\\"";
}
else
{
    $regdatesel = " selected=\\"selected\\"";
}
elseif($by == "rating")
{
    $ratingsel = " selected=\\"selected\\"";
}
if($order == "DESC")
{
    $descsel = " selected=\\"selected\\"";
}
else
{
    $ascsel = " selected=\\"selected\\"";
}

if($usersearch)
{
    $query = $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) WHERE u.username LIKE '%$usersearch%' ORDER BY u.$by $order LIMIT $start, $settings[membersperpage]");
}
else
{
    $query = $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) ORDER BY u.$by $order LIMIT $start, $settings[membersperpage]");
}

while($users = $db->fetch_array($query))
{
    if($users['website'] == "" || $users['website'] == "http://")
    {
        $usersite = "";
    }
    else
    {
        $usersite = "<a href=\\"$users[website]\\" target=\\"_blank\\"><img src=\\"$theme[imgdir]/www.gif\\" border=0></a>";
    }
    $users['location'] = $users[fid1];
    $users['location'] = stripslashes($users['location']);
    if($users['hideemail'] == "yes")
    {
        $useremail = "";
    }
    else
    {
        $useremail = "<a href=\\"member.php?action=emailuser&uid=$users[uid]\\"><img src=\\"$theme[imgdir]/email.gif\\" border=\\"0\\" /></a>";
    }
    $users['regdate'] = mydate($settings['dateformat'], $users['regdate']);
    $users['username'] = formatname($users['username'], $users['namestyle']);
    eval("\\$member .= \\"".$templates->get("memberlist_row")."\\";");
}

// just in case there's no matching search results, or no registered members
if(!$member)
{
    $member = "<tr>\\n<td colspan=\\"6\\" align=\\"center\\" class=\\"trow1\\"><font>No members found.</font></td>\\n</tr>";
}

eval("\\$memberlist = \\"".$templates->get("memberlist")."\\";");
outputpage($memberlist);
?>
its because that isn't line 84, its 39 Toungue But thats not the prob anyway.

Line 76:
PHP Code:
elseif($by == "username")
{
$usernamesel " selected=\\"selected\\"";
}
else
{
$regdatesel " selected=\\"selected\\"";
}
elseif(
$by == "rating")
{
$ratingsel " selected=\\"selected\\"";
}
if(
$order == "DESC"
should be
PHP Code:
elseif($by == "username")
{
    
$usernamesel " selected=\\"selected\\"";
}
elseif(
$by == "rating")
{
    
$ratingsel " selected=\\"selected\\"";
}
else
{
    
$regdatesel " selected=\\"selected\\"";
}
if(
$order == "DESC"
You put the rating select option in the wrong place. Once fixed, it should work.

Full code:
PHP Code:
<?php
/**
* MyBulletinBoard (MyBB)
* Copyright � 2004 MyBulletinBoard Group, All Rights Reserved
*
* Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html
*
*/

$templatelist "memberlist,memberlist_row";
require 
"./global.php";

$userpermissions getuserpermissions($mybb['uid']);
if(
$userpermissions['canviewmemberlist'] == "no")
{
nopermission();
}

if(
$by != "regdate" && $by != "postnum" && $by != "username" && $by != "rating")
{
if(
$usersearch)
{
$by "username";
}
else
{
$by "regdate";
}
}

if(
$order != "DESC" && $order != "ASC")
{
// top posters first
if($by == "postnum")
{
$order "DESC";
}
elseif(
$by == "rating")
{
$order "ASC";
}
else
{
$order "ASC";
}
}

if(
$usersearch)
{
$query $db->query("SELECT COUNT(*) FROM users WHERE username LIKE '%$usersearch%'");
$linkaddon "&usersearch=$usersearch";
}
else
{
$query $db->query("SELECT COUNT(*) FROM users");
$linkaddon "";
}

$num $db->result($query0);
$multipage multipage($num$settings['membersperpage'], $page"memberlist.php?by=$by&order=$order$linkaddon");
if(
$page)
{
$start = ($page 1) * $settings['membersperpage'];
}
else
{
$start 0;
$page 1;
}

if(
$by == "postnum")
{
$postnumsel " selected=\\"selected\\"";
}
elseif(
$by == "username")
{
    
$usernamesel " selected=\\"selected\\"";
}
elseif(
$by == "rating")
{
    
$ratingsel " selected=\\"selected\\"";
}
else
{
    
$regdatesel " selected=\\"selected\\"";
}
if(
$order == "DESC")
{
$descsel " selected=\\"selected\\"";
}
else
{
$ascsel " selected=\\"selected\\"";
}

if(
$usersearch)
{
$query $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) WHERE u.username LIKE '%$usersearch%' ORDER BY u.$by $order LIMIT $start$settings[membersperpage]");
}
else
{
$query $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) ORDER BY u.$by $order LIMIT $start$settings[membersperpage]");
}

while(
$users $db->fetch_array($query))
{
if(
$users['website'] == "" || $users['website'] == "http://")
{
$usersite "";
}
else
{
$usersite "<a href=\\"$users[website]\\" target=\\"_blank\\"><img src=\\"$theme[imgdir]/www.gif\\" border=0></a>";
}
$users['location'] = $users[fid1];
$users['location'] = stripslashes($users['location']);
if(
$users['hideemail'] == "yes")
{
$useremail "";
}
else
{
$useremail "<a href=\\"member.php?action=emailuser&uid=$users[uid]\\"><img src=\\"$theme[imgdir]/email.gif\\" border=\\"0\\" /></a>";
}
$users['regdate'] = mydate($settings['dateformat'], $users['regdate']);
$users['username'] = formatname($users['username'], $users['namestyle']);
eval(
"\\$member .= \\"".$templates->get("memberlist_row")."\\";");
}

// just in case there's no matching search results, or no registered members
if(!$member)
{
$member "<tr>\\n<td colspan=\\"6\\" align=\\"center\\" class=\\"trow1\\"><font>No members found.</font></td>\\n</tr>";
}

eval(
"\\$memberlist = \\"".$templates->get("memberlist")."\\";");
outputpage($memberlist);
?>
Thanx a lot k776 . I got it worked now. But see the image attached, stars are also there but numbers appear as well. How can I get rid of these numbers while retaining the stars. Thanx Smile
do the numbers show before or after you sort them??
The page is set to show members by ratings by default.
Have you followed the steps in this post too?

http://www.mybbmods.com/forum/showthread...586#pid586
ok, here is a code using the one above and the one mentioned at the other post MM said above.

The code below:

Sorts members by rating,
Displays members by rating,
Descendes members by rating (unrated members at the bottom of the list)

So try this complete code:

(If you get any problems, let us know Smile (although, all that code is MM's and shouldn't be buggy, I just put them in the place they are supposed to go and changed a setting to suit what you asked for. So it should all work now.)
PHP Code:
<?php
/**
* MyBulletinBoard (MyBB)
* Copyright � 2004 MyBulletinBoard Group, All Rights Reserved
*
* Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html
*
*/

$templatelist "memberlist,memberlist_row";
require 
"./global.php";

$userpermissions getuserpermissions($mybb['uid']);
if(
$userpermissions['canviewmemberlist'] == "no")
{
nopermission();
}

if(
$by != "regdate" && $by != "postnum" && $by != "username" && $by != "rating")
{
if(
$usersearch)
{
$by "username";
}
else
{
$by "regdate";
}
}

if(
$order != "DESC" && $order != "ASC")
{
// top posters first
if($by == "postnum")
{
$order "DESC";
}
elseif(
$by == "rating")
{
$order "DESC";
}
else
{
$order "ASC";
}
}

if(
$usersearch)
{
$query $db->query("SELECT COUNT(*) FROM users WHERE username LIKE '%$usersearch%'");
$linkaddon "&usersearch=$usersearch";
}
else
{
$query $db->query("SELECT COUNT(*) FROM users");
$linkaddon "";
}

$num $db->result($query0);
$multipage multipage($num$settings['membersperpage'], $page"memberlist.php?by=$by&order=$order$linkaddon");
if(
$page)
{
$start = ($page 1) * $settings['membersperpage'];
}
else
{
$start 0;
$page 1;
}

if(
$by == "postnum")
{
$postnumsel " selected=\\"selected\\"";
}
elseif(
$by == "username")
{
    
$usernamesel " selected=\\"selected\\"";
}
elseif(
$by == "rating")
{
    
$ratingsel " selected=\\"selected\\"";
}
else
{
    
$regdatesel " selected=\\"selected\\"";
}
if(
$order == "DESC")
{
$descsel " selected=\\"selected\\"";
}
else
{
$ascsel " selected=\\"selected\\"";
}

if(
$usersearch)
{
$query $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) WHERE u.username LIKE '%$usersearch%' ORDER BY u.$by $order LIMIT $start$settings[membersperpage]");
}
else
{
$query $db->query("SELECT u.*, f.*, g.namestyle FROM users u LEFT JOIN userfields f ON (f.ufid=u.uid) LEFT JOIN usergroups g ON (g.gid=u.usergroup) ORDER BY u.$by $order LIMIT $start$settings[membersperpage]");
}

while(
$users $db->fetch_array($query))
{
if(
$users['rating'])
{
    
$rateinfo explode("|"$users['rating']);
    
$users['rating'] = round($rateinfo[0] / $rateinfo[1]);
    for(
$i 1$i <= $users['rating']; $i++)
    {
        
$rating .= "<img src=\\"$theme[imgdir]/star.gif\\" border=\\"0\\" title=\\"$users[ratingout of 5\\" />";
    }
}
else
{
    
$rating "Not Yet Rated";
}
if(
$users['website'] == "" || $users['website'] == "http://")
{
$usersite "";
}
else
{
$usersite "<a href=\\"$users[website]\\" target=\\"_blank\\"><img src=\\"$theme[imgdir]/www.gif\\" border=0></a>";
}
$users['location'] = $users[fid1];
$users['location'] = stripslashes($users['location']);
if(
$users['hideemail'] == "yes")
{
$useremail "";
}
else
{
$useremail "<a href=\\"member.php?action=emailuser&uid=$users[uid]\\"><img src=\\"$theme[imgdir]/email.gif\\" border=\\"0\\" /></a>";
}
$users['regdate'] = mydate($settings['dateformat'], $users['regdate']);
$users['username'] = formatname($users['username'], $users['namestyle']);
eval(
"\\$member .= \\"".$templates->get("memberlist_row")."\\";");
unset(
$rating);
}

// just in case there's no matching search results, or no registered members
if(!$member)
{
$member "<tr>\\n<td colspan=\\"6\\" align=\\"center\\" class=\\"trow1\\"><font>No members found.</font></td>\\n</tr>";
}

eval(
"\\$memberlist = \\"".$templates->get("memberlist")."\\";");
outputpage($memberlist);
?>

Then from your admin control panel, look for this code in the "memberlist" template:
Code:
<tr>
<td class="thead"><b>Username:</b></td>
<td class="thead" align="center"><b>E-mail:</b></</td>
<td class="thead" align="center"><b>Website:</b></</td>
<td class="thead"><b>Location:</b></</td>
<td class="thead" align="center"><b>Joined:</b></</td>
<td class="thead"><b>Posts:</b></</td>
</tr>
Replace the above with this:
Code:
<tr>
<td class="thead"><b>Username:</b></td>
<td class="thead"><b>Rating:</b></td>
<td class="thead" align="center"><b>E-mail:</b></</td>
<td class="thead" align="center"><b>Website:</b></</td>
<td class="thead"><b>Location:</b></</td>
<td class="thead" align="center"><b>Joined:</b></</td>
<td class="thead"><b>Posts:</b></</td>
</tr>

Next, look for these two lines in the same template:
Code:
<form action="memberlist.php" method="post">
<td align="center" colspan="6" class="trow2">
Highlight, and replace them with these two lines:
Code:
<form action="memberlist.php" method="post">
<td align="center" colspan="7" class="trow2">

Then open your "memberlist_row" template, and highlight everything. Replace it with this:
Code:
<tr>
<td class="trow1"><a href="member.php?action=profile&uid=$users[uid]">$users[username]</a></td>
<td class="trow2">$rating</td>
<td class="trow1">$useremail</td>
<td class="trow2">$usersite</td>
<td class="trow1">$users[location]</td>
<td class="trow2">$users[regdate]</td>
<td class="trow1">$users[postnum]</td>
</tr>

If you get any problems, let us know Smile (although, all that code is MM's and shouldn't be buggy, I just put them in the place they are supposed to go and changed a setting to suit what you asked for. So it should all work now.)
Everything is working fine now. Thanx a lot k776 and MM Smile
np, glad I could help Smile what is the url to your board anyway?? I have heard about it so much but never been to it.
k776 Wrote:what is the url to your board anyway?? I have heard about it so much but never been to it.

waooooooo...I didn't know my board is already a hit Smile Actually I am still playing around with the layout and with different options. It's still not ready and will never be ready until I get another mod from your guys Big Grin That is headlines of posts in users' profile. MM is working on that Smile. I would definitely invite you to have a look at my board when it's ready. Again lots of thanx man Smile