display ranking on profile page

u1stgames

New Member
License Active
hello there,

i am just wondering if there is a shortcode/variable for the current rank, to be displayed on the listing profile/stats page?

basically just under the listing title, and under the "member since (date)", i would like to have "ranked 3rd of 107 (listings)".

also, i have some custom join fields, so it would be great to have it say "ranked 14th of 107 (listings). ranked 3rd of 43 (custom join field)"

thank you
 

Basti

Administrator
Staff member
For rank you can use {$old_rank}, but that is a cached value, so properbly better to use the attached plugin. Depends on your needs i guess.
{$details_rank} if you use the plugin

also, i have some custom join fields, so it would be great to have it say "ranked 14th of 107 (listings). ranked 3rd of 43 (custom join field)"
That is quite custom, could be included in your other topic if interested.
 

Attachments

u1stgames

New Member
License Active
Hey basti!

Thanks for the reply.

DetailsRank is exactly what I needed, and I'm able to easily extend the plugin by editing details_build_page.php to this:

PHP:
// Get the ranking method, default to pageviews
$ranking_method = $CONF['ranking_method'];

// Make ORDER BY clause
$order_by = $this->rank_by($ranking_method)." DESC, unq_{$ranking_method}_overall DESC";

$TMPL['details_rank'] = 1;
$result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
while (list($username) = $DB->fetch_array($result))
{
    if($username == $TMPL['username'])
    {
        break;
    }
    $TMPL['details_rank']++;
}

//ok now for category

$TMPL['category_rank'] = 1;
$result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND sites.category='{$TMPL['category']}' AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
while (list($username) = $DB->fetch_array($result))
{
    if($username == $TMPL['username'])
    {
        break;
    }
    $TMPL['category_rank']++;
}


//...and for platform

$TMPL['platform_rank'] = 1;
$result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND sites.acf_platform='{$TMPL['acf_platform']}' AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
while (list($username) = $DB->fetch_array($result))
{
    if($username == $TMPL['username'])
    {
        break;
    }
    $TMPL['platform_rank']++;
}
this allows me to rank overall, rank by the category i have setup, and also rank by the custom join field i am using :)
 

Basti

Administrator
Staff member
Great, you should however make sure to properly database escape values. If category includes a quote for example it would break everything
Code:
$result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND sites.category='{$TMPL['category']}' AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
turns into
Code:
$category_rank_sql = $DB->escape($TMPL['category'], 1);
$result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND sites.category='{$category_rank_sql}' AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
Same thing should be applied to the platform rank :)
 
Top