Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:22:26+00:00 2026-05-24T11:22:26+00:00

I’m trying to make a tracking program for an online game, and I need

  • 0

I’m trying to make a tracking program for an online game, and I need to sort gained experience by whoever has gained the most experience.

However, what happens is, say I’m tracking the users (a, b, c, d, e, f, g), and the users (b, e, g) have gained 0 experience. It will show (b) 3 times, because there is 3 people that have gained 0 experience and (b) is the first person, out of 3, that have gained 0 experience. I can’t think of how to show you just what I’m doing without the actual file, so here’s the file’s contents:

<?php

    $participants = array("Quuxx", "Aeterna", "Ts Danne", "Marsman", "PFC Mage");

    $skills = array("overall", "attack", "defense", "strength", "constitution", "ranged", "prayer", "magic", "cooking", "woodcutting", "fletching", "fishing", "firemaking", "crafting", "smithing", "mining", "herblore", "agility", "thieving", "slayer", "farming", "runecrafting", "hunter", "construction", "summoning", "dungeoneering");

    $database = mysql_connect("mysql.alwaysdata.com", "*", "*");

    if (!$database) {
        die('Could not connect to database: ' . mysql_error());
    }

    mysql_select_db("tracker_tkoblitz", $database);

    if (isset($_GET['track'])) {
        for ($i = 0; $i < count($participants); $i++) {
            startTracker($participants[$i]);
        }
    }

    shit(array_search($_GET['skill'], $skills));

    function startTracker($username) {
        $stats = getStats($username);
        mysql_query("INSERT IGNORE INTO stats (username, stats) VALUES ('$username', '$stats')");
    }

    function grabStats($username) {
        $query = mysql_query("SELECT * FROM stats WHERE username LIKE '$username'");
        while ($row = mysql_fetch_array($query)) {
            return $row['stats'];
        }
    }

    function shit($lol) {
        global $participants, $skills;
        sort($participants);
        echo '<head><title>Fight Tracker</title><link rel="stylesheet" href="style.css"></head><body><div align="center"><img src="http://www.runehead.com/clans/banners/clansolace-6617078.png"><table id="atable"><thead><tr><th scope="col">Username</th><th scope="col">Skill</th><th scope="col">Level</th><th scope="col">Starting experience</th><th scope="col">Ending experience</th><th scope="col">Gained experience</th></tr></thead>';
        for ($i = 0; $i < count($participants); $i++) {
            $level = getStat(grabStats($participants[$i]), 1, $lol);
            $starting = getStat(grabStats($participants[$i]), 2, $lol); //2nd param: rank,lvl,xp
            $stats = getStats($participants[$i]); //2nd param: rank,lvl,xp
            $current = getStat($stats, 2, $lol);
            $gained[] = $current - $starting;
            //echo '<tr><td class="odd">' . $participants[$i] . '</td><td class="odd"><img src="images/' . $skills[$lol] . '.png"></td><td class="odd">' . number_format($level) . '</td><td class="odd">' . number_format($starting) . '</td><td class="odd">' . number_format($current) . '</td><td class="odd">' . number_format($gained) . '</td></tr>';
            $statss[] = array($participants[$i], $level, $starting, $current, $gained[$i]);
        }
        arsort($gained);
        foreach ($gained as $gain) {
            $skillData = getSkillData($gain, $statss);
            $name = $skillData[0];
            $level = $skillData[1];
            $start = $skillData[2];
            $current = $skillData[3];
            $gainedXP = $skillData[4];
            echo '<tr><td class="odd">' . $name . '</td><td class="odd"><img src="images/' . $skills[$lol] . '.png"></td><td class="odd">' . number_format($level) . '</td><td class="odd">' . number_format($start) . '</td><td class="odd">' . number_format($current) . '</td><td class="odd">' . number_format($gainedXP) . '</td></tr>';
        }
        echo '</tbody></table></div><br><form name="skill_select" action="view_tracker.php" method="GET"><div align="center"><font color="#03F">View a different skill: </font><select name="skill"><option value="overall">Overall</option><option value="attack">Attack</option><option value="defence">Defence</option><option value="strength">Strength</option><option value="constitution">Constitution</option><option value="ranged">Ranged</option><option value="prayer">Prayer</option><option value="magic">Magic</option><option value="cooking">Cooking</option><option value="woodcutting">Woodcutting</option><option value="fletching">Fletching</option><option value="fishing">Fishing</option><option value="firemaking">Firemaking</option><option value="crafting">Crafting</option><option value="smithing">Smithing</option><option value="mining">Mining</option><option value="herblore">Herblore</option><option value="agility">Agility</option><option value="thieving">Thieving</option><option value="slayer">Slayer</option><option value="farming">Farming</option><option value="runecrafting">Runecrafting</option><option value="hunter">Hunter</option><option value="construction">Construction</option><option value="summoning">Summoning</option><option value="dungeoneering">Dungeoneering</option></select>      <input type="submit" value="View" /></div></form></body>';
    }

    function read($file) {
        if (($handle = fopen($file, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                for ($c = 0; $c < count($data); $c++) {
                    $lines[] = $data[$c];
                }
            }
            fclose($handle);
        }
        return $lines;
    }

    function getSkillData($gain, $stats) {
        foreach ($stats as $stat) {
            if ($stat[4] == $gain) {
                return $stat;
            }
        }
    }

    function getStats($username) {
        $curl = curl_init();

        curl_setopt ($curl, CURLOPT_URL, "http://hiscore.runescape.com/index_lite.ws?player=" . $username);
        curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0", rand(4, 5)));
        curl_setopt ($curl, CURLOPT_HEADER, (int) $header);
        curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt ($curl, CURLOPT_VERBOSE, 1);

        $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $output = curl_exec($curl);

        curl_close ($curl);

        if (strstr($output, "<html><head><title>")) {
            return false;
        }
        return $output;
    }

    function getStat($stats, $row, $skill) {
        $stats = explode("\n", $stats);
        $levels = explode(",", $stats[$skill]);
        return $levels[$row];
    }

    mysql_close($database);

?>

Here’s a live demo of that same exact file: http://tracker.alwaysdata.net/solace/view_tracker.php

Notice PFC Mage is there twice, when it should show PFC Mage and Quuxx separately. Everything else sorts just fine, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:22:28+00:00Added an answer on May 24, 2026 at 11:22 am

    Problem is here:

    foreach ($stats as $stat) {
        if ($stat[4] == $gain) {
            return $stat;
        }
    }
    

    This function returns first element that satisfies condition. So, if you have two or more people with equivalent exp you always get only the first. Consider passing another parameter, like nth-occurence or startIndex, like this:

    function getSkillData($gain, $stats, $nthOccurence=1) {
        $occurence = 0;
        foreach ($stats as $stat) {
            if ($stat[4] == $gain) {
                 ++$occurence;
                 if ($occurence == $nthOccurence)
                      return $stat;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I need to clean up various Word 'smart' characters in user input, including but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.