Jump to content

Aeterna

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Aeterna's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys, 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 it is: <?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?
  2. Hi all, I'm trying to sort my array, which is something along the lines of: $myArray = array('Test' => 120, 'Tust' => 394, 'Lap' => 439493); What I'm trying to do, is sort the keys (which I've done), and then add the names (Test, Tust, Lap) to an array in the order the keys ordered them, so that I can display them in the order they belong in (the order the keys put them in). I can't figure it out for the life of me... here's what I'm currently using: function associative_push($arr, $tmp) { if (is_array($tmp)) { foreach ($tmp as $key => $value) { $arr[$key] = $value; } return $arr; } return false; } $participants = array('Lap', 'Test', 'Tust'); $starting = array(); $current = array(); for ($a = 0; $a < count($participants); $a++) { $starting = associative_push($starting, array($participants[$a] => "testing: $a")); } for ($b = 0; $b < count($participants); $b++) { $current = associative_push($current, array($participants[$b] => "testing: $b")); } arsort($starting); arsort($current); for ($i = 0; $i < count($participants); $i++) { $startingExperience = $starting[$participants[$i]]; $currentExperience = $current[$participants[$i]]; // table stuff here (bunch of unnecessary code) } I'm trying to get it so that 'Lap' would be the first table entry, 'Tust' would be the second, and 'Test' the third. Any ideas?
  3. I see, so if I was to use an auto increment, how could I match the username and experience to that id? I'm sorry if the question is really silly, I've never really done MySQL so I don't completely understand tables/rows/columns (they all seem like the same thing to me). The only way I know how to do stuff is to execute the query, such as this (may not be the best way but it's the best way I could think of): function startTracker($database) { global $skills, $participants; for ($i = 0; $i < count($participants); $i++) { for ($a = 0; $a < count($skills); $a++) { mysql_query("INSERT INTO $skills[$a] (username, experience) VALUES ('$participants[$i]', '" . getStats($participants[$i], $a, 2) . "')"); } } } Then I grab it by: function grabExperience($user, $table) { while ($row = mysql_fetch_array(mysql_query("SELECT * FROM $table WHERE username='" . $user . "'"))) { return $row['experience']; } }
  4. I need for there to be a separate database for each tracker because they're all different, and there's going to be quite a few of them. If I was going to add a new column, and was to make it 'username_id', 'experience_id', how would I assign new ids to be 1 higher than the previous column? Meaning, the first tracker is 'username_1', 'experience_1', then 'username_2', 'experience_2', and so on.
  5. Hello, I'm currently trying to make a tracking program, which grabs a users experience from a website and inserts it into an MySQL database, I have that all working fine, but I'm kind of stumped on something.... I would like to be able to make it so that multiple trackers can be in play at one time, and multiple databases(?) would be used to hold the data. Currently, what I have now, is "mron_tracker" as my database, "xxx" (1-25, all different words) are tables, and then the username and experience are held within the table. What I'd like to do, or know how to do, is make it so that a new database "mron_tracker_x" is created when creating a new tracker. I'd like it to work so that, when one tracker is created, its id is "1", the next one is "2", after that is "3", and so on. Here's a picture of how the structure is in PHPMyAdmin: If someone could point me in the right direction as to what I should look for, I'd be extremely greatful. If you need anything cleared up let me know and I'll do my best to explain it. Thank-you in advance, Ron
  6. Oh, I see. Well a friend of mine is letting me use his database from his forums and I'll go ahead and use the users that are registered. Thanks for the tips and insight, I'll be sure to use it! Thank you for all the help. :^D
  7. Hm, well if I was to do that is there any way to check if the image was uploaded by the logged in user?
  8. Hello everyone, I've recently started to look into some PHP programming and thought I would try and make an image uploader service. It's going well, I was just wondering if there was any way to make it so that only the uploader could delete a their file. (I do not have accounts yet, but will in the future.) Here are the files that I'm using (Don't be afraid to give me some constructive criticism or ideas! I could use it!): index.php <?php if ($_REQUEST[completed] == 1) { $newname = uniqid(); move_uploaded_file($_FILES['mailfile']['tmp_name'], "images/$newname.jpg"); echo '<center><h3>Image successfully uploaded!</h3>Direct Link<br /><input type="text" size="30" value="http://aeterna.ulmb.com/uploader/images/' .$newname . '.jpg"><br /><br />Message Boards<br /><input type="text" size="30" value="[img=http://aeterna.ulmb.com/uploader/images/' . $newname . '.jpg]"><br /><br />Deletion link<br /><a href="http://aeterna.ulmb.com/uploader/delete.php?file=' . $newname . '">http://aeterna.ulmb.com/uploader/delete.php?file=' . $newname . '</a></center>'; } ?> <html> <head> <meta content="text/html;charset=iso-8859-1" http-equiv="Content-Type" /> <title>Image Uploader</title> </head> <body> <div align="center"> <?php if ($_REQUEST[completed] != 1) { ?> <h1>Image Uploader</h1> <form enctype=multipart/form-data method=post> <input type=hidden name=MAX_FILE_SIZE value=1500000> <input type=hidden name=completed value=1>Image: <input type=file name=mailfile value="Browse..."> <br /> <br /> <input type=submit value="Upload"> </form> <?php } ?> </div> </body> </html> delete.php <?php $file = $_GET['file']; if (!unlink("images/$file.jpg")) { echo "<center><h1>There was an error deleting your file ($file).</h1></center>"; } else { echo "<center><h1>Your file has been deleted upon request.</h1></center>"; } ?> Here's a live demo, as you can see anyone can delete any file (I just have it as the file name because I honestly can't think of ANY other way to do it. http://aeterna.ulmb.com/uploader/index.php Thanks in advance, ~Aeterna
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.