Page 1 of 1

modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 5:06 pm
by cbsarge
I'm trying to modify the top_list module to not display the first 4 player IDs. Those are developer accounts and their stats are a little ridiculous so I'd rather it only list the real players. How would I modify this query?

Code: Select all

$result = $db->Execute("select id,name from user_stat_types where max_value is null and display_code is null order by name");

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 5:52 pm
by KyleMassacre
Well you would need the query that selects the user id from the stats and gets the names from the users table. In there you can add something like:

Code: Select all

$array = array(2,3,4,5);
//the db query is here and the loop while(!$result->EOF) {
    if(!in_array($array,$result->id)
    {
        //print the contents
    }
    $result->MoveNext();
//} end of the loop

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 7:45 pm
by cbsarge
Hmmm... after much monkeying around I still am unable to get the results to not list the IDs in the array. :oops:

Code: Select all

<?php
$array = array(2,3,4);
$result = $db->Execute("select id,name from user_stat_types where max_value is null and display_code is null order by name");
$statNames = array();
$nb = array($db->Execute("select id from users"));
while (! $result->EOF)
{
	$statNames[$result->fields[0] + 0] = $result->fields[1];
	$result->MoveNext();
}
$result->Close();

echo "<table class='plainTable'>";
echo "<tr valign='top'>";
foreach ($statNames as $statId => $statName)
{
    echo "<td>";
    TableHeader($statName);
    echo "<table class='plainTable'>";
    $result = $db->Execute("select users.username, user_stats.value from user_stats left join users on users.id = user_stats.user_id where stat_type = ? order by value desc limit 0,50", $statId);
    $l = 0;
    while (! $result->EOF)
    {
    if(!in_array($array,$nb))
    {
		if ($l % 2 == 0)
            echo "<tr class='evenLine'>";
        else
            echo "<tr class='oddLine'>";
        echo "<td>{$result->fields[0]}</td><td>{$result->fields[1]}</td>";
        echo "</tr>";
	}
        $result->MoveNext();
        $l ++;
    }
    echo "</table>";
    TableFooter();
    echo "</td>";
}
echo "</tr>";
echo "</table>";
?>

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 8:00 pm
by KyleMassacre
Try:

Code: Select all

<?php
$array = array(2,3,4);
$result = $db->Execute("select id,name from user_stat_types where max_value is null and display_code is null order by name");
$statNames = array();
while (! $result->EOF)
{
    $statNames[$result->fields[0] + 0] = $result->fields[1];
    $result->MoveNext();
}
$result->Close();

echo "<table class='plainTable'>";
echo "<tr valign='top'>";
foreach ($statNames as $statId => $statName)
{
    echo "<td>";
    TableHeader($statName);
    echo "<table class='plainTable'>";
    $result = $db->Execute("select users.username, user_stats.value, users.id from user_stats left join users on users.id = user_stats.user_id where stat_type = ? order by value desc limit 0,50", $statId);
    $l = 0;
    while (! $result->EOF)
    {
        if(!in_array($array,$result->id))
        {
            if ($l % 2 == 0)
                echo "<tr class='evenLine'>";
            else
                echo "<tr class='oddLine'>";
            echo "<td>{$result->fields[0]}</td><td>{$result->fields[1]}</td>";
            echo "</tr>";
        }
        $result->MoveNext();
        $l ++;
    }
    echo "</table>";
    TableFooter();
    echo "</td>";
}
echo "</tr>";
echo "</table>";
?>

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 8:07 pm
by cbsarge
Error: Un-handled Exception: Can't get property id.
Error in "/hermes/bosnaweb03a/b2751/ipg.cbsargecom/VillainsandHeroes/libs/db.php"
Line 428
Error in /hermes/bosnaweb03a/b2751/ipg.cbsargecom/VillainsandHeroes/libs/common.php
Line 554
Error in /hermes/bosnaweb03a/b2751/ipg.cbsargecom/VillainsandHeroes/index.php
Line 331

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 9:47 pm
by KyleMassacre
Oops that's my lame fault, rookie mistake. For the "in_array()" change it to $result->fields[2] instead of $result->id

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 10:47 pm
by cbsarge
that caused a error saying I provided an integer and it was expecting an array. :|

Code: Select all

Error: in_array() expects parameter 2 to be array, integer given

Re: modify Top List module to not include dev accounts

Posted: Thu Oct 29, 2015 11:37 pm
by KyleMassacre
My bad again. I got the needle and haystack messed up. Switch the parameters around in the in_array()

Re: modify Top List module to not include dev accounts

Posted: Fri Oct 30, 2015 12:54 pm
by cbsarge
That fixed it - thanks for all the help Kyle!