Jump to content

FlameDra

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Everything posted by FlameDra

  1. Okay so I get a LOT of data, some of the chunks are in the following format : |- |style="text-align:left;" bgcolor="#242424"|{{ci|Ahri}} |bgcolor="#242424"|Mage |bgcolor="#102E00"|40 |bgcolor="#420300"|30 |bgcolor="#000A4C"|80 |bgcolor="#30004C"|80 |bgcolor="#242424"|2011-12-14 |bgcolor="#242424"|6300 |bgcolor="#242424"|975 Now is there any way (by coding some regex or something) to get whats inside the {{ci|Ahri}} ? As in, I need a way to take {{ci|Ahri}} and output Ahri and then store it in an array, which I will pass into another file_get_contents.
  2. You've already got the data... what's the problem? 1. I have the data of one champion, I need some way to do this for every champion. 2. Need a way to use the data and make variables which can be input into the local database by PHP.
  3. I was just reading up on file_get_contents just now I'm not too familiar with objects yet, but I'm decent with arrays I guess. Also, I thought about getting the data from their main site : http://na.leagueoflegends.com/champions But there is no way to turn that into XML for me. Is there any way to do a HTTP GET query to turn the page into XML and then use it with cURL in PHP? I mean, I would like to get into the divs and get the data there. I also found this : https://github.com/promisedlandt/loldata/blob/9c214067af09b5fb305d765701af83c7c4f93f4e/lib/loldata/champion.rb Which does something similar, but is in some other language.
  4. Okay so I've been poking around the Wikia API and this is what I've come up with so far. For this example, I'm attempting to get all the data on Caitlyn, the Sheriff of Piltover. After digging around the documentation, I found out that in order to get all the data on that page in XML format I have to run the following query : http://leagueoflegends.wikia.com/api.php?action=query&titles=Caitlyn_the_Sheriff_of_Piltover&prop=revisions&rvprop=content&format=xml Below, is the result that I get : <api><query><normalized><n from="Caitlyn_the_Sheriff_of_Piltover" to="Caitlyn the Sheriff of Piltover"/></normalized><pages><page pageid="117773" ns="0" title="Caitlyn the Sheriff of Piltover"><revisions><rev xml:space="preserve">{{C-top}}{{infobox champion | name = Caitlyn | image = File:CaitlynSquare.png | title = The Sheriff of Piltover | herotype = {{Attributes|Ranged|Carry}} | date = January 4, 2011<ref>[[V1.0.0.108]]</ref> | health = 40 | attack = 80 | spells = 40 | difficulty = 40 | hp = 390 (+80) | mana = 255 (+35) | damage = 47 (+3) | range = 650 | armor = 13 (+3.5) | magicresist = 30 (+0) | attackspeed = 0.668 (+3.0%) | healthregen = 4.75 (+0.55) | manaregen = 6.5 (+0.55) | speed = 300 | IP = 6300 | RP = 975 }}'''Caitlyn, the Sheriff of Piltover''' is a [[champion]] in [[League of Legends]].<ref>[http://www.leagueoflegends.com/champions/51/caitlyn_the_sheriff_of_piltover Caitlyn's profile page] at [[leagueoflegends.com]]</ref> Last time on Rotation: May 8th, 2012 ==Abilities== {{Abilities |ver = v1.0.0.129 |innatename = Headshot |innateinfo = '''(Innate)''': Every {{pp|3|8th|7th|6th|1|7|13}} auto-attack is enhanced to be a headshot, dealing 150% damage to a champion or 250% damage to a minion or monster. Attacks from brush increase the attack counter by two instead of one. |firstname = Piltover Peacemaker |firstinfo = '''(Active)''': Caitlyn revs up her rifle for 1 second to unleash a penetrating shot in a line which will deal physical damage to all targets hits. It will deal 15% less damage for each subsequent target hit, down to a minimum of 40% damage dealt. *'''Range:''' 1300 |firstlevel = {{level up|Cost|mana|50|60|70|80|90}} {{level up|Cooldown|seconds|10|9|8|7|6}} {{level up|Physical Damage|(+1.3 per attack damage)|20|60|100|140|180}} {{level up|Minimum Physical Damage|(+0.52 per attack damage)|8|24|40|56|72}} |secondname = Yordle Snap Trap |secondinfo = '''(Active)''': Caitlyn sets a trap at the target nearby location. The trap triggers when a champion walks over it. This trap is visible to both allies and enemies. When sprung, the trap immobilizes the champion for 1.5 seconds, dealing magic damage over the duration and additionally revealing the target for 9 seconds. Caitlyn can set up to 3 traps and they last 4 minutes. When she sets a trap once the cap has been reached, the oldest trap will deactivate itself. *'''Cost:''' 50 mana *'''Placement Range:''' 800 *'''Activation Range:''' 135 |secondlevel = {{level up|Cooldown|seconds|20|17|14|11|8}} {{level up|Total Magic Damage|(+0.6 per ability power)|80|130|180|230|280}} |thirdname = 90 Caliber Net |thirdinfo = '''(Active)''': Caitlyn fires a heavy net in front of her, knocking herself back in the opposite direction. The net will slow down the first target hit by 50% and will deal magic damage to it. *'''Cost:''' 75 mana *'''Range:''' 1000 *'''Knockback Distance:''' 400 |thirdlevel = {{level up|Cooldown|seconds|18|16|14|12|10}} {{level up|Magic Damage|(+0.8 per ability power)|80|130|180|230|280}} {{level up|Slow Duration|seconds|1|1.25|1.5|1.75|2}} |ultiname = Ace in the Hole |ultiinfo = '''(Active)''': Caitlyn marks an enemy champion at a huge range and channels for 2 seconds to line up the perfect shot, providing vision of the target for the duration. She then fires the projectile to deal massive physical damage. Enemy champions can intercept the bullet for their ally. *'''Cost:''' 100 mana *'''Projectile Speed:''' 3200 |ultilevel = {{level up|Cooldown|seconds|90|75|60}} {{level up|Range||1900|2050|2200}} {{level up|Physical Damage|(+2.0 per bonus attack damage)|250|475|700}} }} ==References== {{Reflist}} {{C-bot}} [[Category:2011 release]] [[Category:Season One release]] [[Category:Released Champion]]</rev></revisions></page></pages></query></api> So what I want to do is to get the XML data (such as the above) on all of the champions, have them formatted, and enter them into my local database. I would like to do it in such a way so that I can do a CRON (as xyph mentioned) which I would run every 2 weeks to overwrite all the data in my database with new ones. Some pointers, please
  5. I thought of many scenarios of gathering data, one of them was to keep a local database which gets the data from the Wiki (via a script or w/e) and writes them to the database. But I have no idea how to achieve that, could you link me to some examples or tutorials?
  6. Thanks for pointing it out, I completely missed that! I got to the following pages : http://leagueoflegends.wikia.com/api.php http://leagueoflegends.wikia.com/wiki/Special:ApiExplorer I'll be reading around and see if I can find something to help me get data from the wiki
  7. I'm trying to make a League of Legends (a video game) community website, both as a personal project and for practice. Now the game has a lot of champions, each of whom have 5 unique abilities. Now, I thought about manually inputting all the details about each champion into a MySQL database, but that would long and tedious, and I don't really have the time for it now. Also, the game patches very oftern (like, once every 2 weeks) which changes many of the stats, etc. of the champion, and it is not possible for me to keep manually updating these every time there is a patch. Fortunately, there is a League of Legends Wiki which has all the data I need in their specific champion pages, which they keep updated per patch. So I was wondering if there was any way to get the data from the divs in the wiki, and have it display on my site. What I want to do in my website is that whenever someone types a champion's name (in a post or whatever), I want it to display a hover-over dialog with some of the champions details. And a lot of other features such as that. In plain English I need a way to : > Tell PHP to go to the wiki's source code on a specific page > Find a specific div container > Get X data from there > Pass X data into a function to display the hover-over I think this way, I would not have to maintain a database as I can leech off the wiki's data. I have not coded anything like this before, so I would like a few pointers as to how to achieve this. Any help will be appreciated!
  8. Yeah, I knew that. Thats why I added player1/player2/player3 as names since they all had to be unique.
  9. Yes, because you have multiple inputs with the same name they form and array inside the $_POST array. Ah, thank you guys! All this makes much more sense to me now.
  10. So, $_POST[] is an array, and $_POST[playerName[]] is an array inside the main $_POST[] array?
  11. But isn't playerName only holding the name of the player and not anything else? How is it a multi-layer array then?
  12. Thanks for taking your time to clear that up. But by the way, shouldn't it be $_POST['playerName[$id]'] instead of $_POST['playerName'][$id]?
  13. I went through that before, but the example was quite different. I don't get what the $id => $name is doing. Could you explain a bit? Sorry if I'm too much trouble. :S
  14. Thanks But could you elaborate the foreach loop a bit more? foreach($_POST['playerName'] AS $id => $name) { echo 'Player '.$name.' has '.round($_POST['playerKills'][$id]/$totalKills*100).'% of total kills. '; // Kill Percentage echo 'He has '.round($_POST['playerDeaths'][$id]/$totalDeaths*100).'% of total deathss. '; // Death Percentage echo 'He has '.round($_POST['playerAssists'][$id]/$totalAssists*100).'% of total assists. <br>'; // Assist Percentage } What is the $id and $name variables and what are they doing?
  15. Hello, Thanks to my new found knowledge of forms, I was able to make the following application! Let me just tell you a bit about what it does. I basically made this to calculate the percentage of the total scores from League of Legends, a game that me and some of my friends play. The game is played with 5 Players per team, and they can each Kill, Die, or Assist people throughout the game. The purpose of this application is to find out the % Kill, % Death and % Assist per Player in a team throughout one game. It calculates this by doing something like a Player1Kills/TotalKills*100 calculation. Here is the code which I wrote : <!-- Author : Soufin 'FlameDra' Rahimeen Date Started : 4/1/2011 --> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>League of Legends - Calculator</title> </head> <body> <form action="" method="POST"> Player 1 : <input type="text" name="player1" value="Player Name"></input> K : <input type="text" name="player1K" value="Kills"></input> D : <input type="text" name="player1D" value="Deaths"></input> A : <input type="text" name="player1A" value="Assists"></input><br /> Player 2 : <input type="text" name="player2" value="Player Name"></input> K : <input type="text" name="player2K" value="Kills"></input> D : <input type="text" name="player2D" value="Deaths"></input> A : <input type="text" name="player2A" value="Assists"></input><br /> Player 3 : <input type="text" name="player3" value="Player Name"></input> K : <input type="text" name="player3K" value="Kills"></input> D : <input type="text" name="player3D" value="Deaths"></input> A : <input type="text" name="player3A" value="Assists"></input><br /> Player 4 : <input type="text" name="player4" value="Player Name"></input> K : <input type="text" name="player4K" value="Kills"></input> D : <input type="text" name="player4D" value="Deaths"></input> A : <input type="text" name="player4A" value="Assists"></input><br /> Player 5 : <input type="text" name="player5" value="Player Name"></input> K : <input type="text" name="player5K" value="Kills"></input> D : <input type="text" name="player5D" value="Deaths"></input> A : <input type="text" name="player5A" value="Assists"></input><br /> <br /> <input type="Submit" value="Submit"></input> <br /> <br /> </form> <?php $totalK = $_POST['player1K'] + $_POST['player2K'] + $_POST['player3K'] + $_POST['player4K'] + $_POST['player5K']; $totalD = $_POST['player1D'] + $_POST['player2D'] + $_POST['player3D'] + $_POST['player4D'] + $_POST['player5D']; $totalA = $_POST['player1A'] + $_POST['player2A'] + $_POST['player3A'] + $_POST['player4A'] + $_POST['player5A']; ?> <br /> <!-- Player 1 Area --> Player <?php echo $_POST['player1']?> has <?php $player1Kpercent = $_POST['player1K']/$totalK*100; echo round("$player1Kpercent") . "%"; ?> of total kills. He has <?php $player1Dpercent = $_POST['player1D']/$totalD*100; echo round("$player1Dpercent") . "%"; ?> of total deaths, and he has <?php $player1Apercent = $_POST['player1A']/$totalA*100; echo round("$player1Apercent") . "%"; ?> of total Assists. <br /> <!-- Player 2 Area --> Player <?php echo $_POST['player2']?> has <?php $player2Kpercent = $_POST['player2K']/$totalK*100; echo round("$player2Kpercent") . "%"; ?> of total kills. He has <?php $player2Dpercent = $_POST['player2D']/$totalD*100; echo round("$player2Dpercent") . "%"; ?> of total deaths, and he has <?php $player2Apercent = $_POST['player2A']/$totalA*100; echo round("$player2Apercent") . "%"; ?> of total Assists. <br /> <!-- Player 3 Area --> Player <?php echo $_POST['player3']?> has <?php $player3Kpercent = $_POST['player3K']/$totalK*100; echo round("$player3Kpercent") . "%"; ?> of total kills. He has <?php $player3Dpercent = $_POST['player3D']/$totalD*100; echo round("$player3Dpercent") . "%"; ?> of total deaths, and he has <?php $player3Apercent = $_POST['player3A']/$totalA*100; echo round("$player3Apercent") . "%"; ?> of total Assists. <br /> <!-- Player 4 Area --> Player <?php echo $_POST['player4']?> has <?php $player4Kpercent = $_POST['player4K']/$totalK*100; echo round("$player4Kpercent") . "%"; ?> of total kills. He has <?php $player4Dpercent = $_POST['player4D']/$totalD*100; echo round("$player4Dpercent") . "%"; ?> of total deaths, and he has <?php $player4Apercent = $_POST['player4A']/$totalA*100; echo round("$player4Apercent") . "%"; ?> of total Assists. <br /> <!-- Player 5 Area --> Player <?php echo $_POST['player5']?> has <?php $player5Kpercent = $_POST['player5K']/$totalK*100; echo round("$player5Kpercent") . "%"; ?> of total kills. He has <?php $player5Dpercent = $_POST['player5D']/$totalD*100; echo round("$player5Dpercent") . "%"; ?> of total deaths, and he has <?php $player5Apercent = $_POST['player5A']/$totalA*100; echo round("$player5Apercent") . "%"; ?> of total Assists. <b /> </body> </html> Just for example, some screenshots. For values input like : The result is : Now, as you can see the code is quite long and may be hard to understand in case I want to expand it in the future. So, I was wondering how I can use functions to make the code more readable and shorter. I'm sorry, I'm not used to using functions (yet). Thanks in advance!
  16. Thanks to everyone who helped! Its finally working! Full code below of anyone interested : post.php <?php require ('resources/DB_connect.php'); $query = mysql_query("SELECT id, title, post FROM post") or die("<b>Your error is:</b><br />\n" . mysql_error()); while ($row = mysql_fetch_assoc($query)) { ?> <h2> <a href="posts.php?=id<?php echo $row['id']; ?>"> <?php echo $row['title']; ?></a></h2> <p> <?php echo $row['post']; ?></p> <?php } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>View Posts</title> </head> <body> </body> </html> I'd recommend other newbies (like me xD) to try this example. I learned a LOT from this! Thank you guys again.
  17. Thanks. The error I now get is : Your error is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''post'' at line 1
  18. My error checker has an error : Warning: mysql_errno() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\form\posts.php on line 7 Warning: mysql_error() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\form\posts.php on line 7 : Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\form\posts.php on line 10
  19. I'm sorry, but I'm really new at this and am not sure how to use that function. But I tried doing : echo mysql_errno($query) . ": " . mysql_error($query). "\n"; But it did not work :/
  20. $query = mysql_query("SELECT id, title, post FROM posts"); Same result
  21. I tried changing it to : $query = mysql_query("SELECT `id`, `title`, `post` FROM `posts` "); and : $query = mysql_query("SELECT id, title, post FROM posts "); It still gave the same error message :S
  22. Well, today I tried displaying the data which the form submits into the database. I made a new file called posts.php : <?php require ('resources/DB_connect.php'); $query = mysql_query("SELECT 'id', 'title', 'post' FROM 'posts' "); while ($row = mysql_fetch_assoc($query)) { ?> <h2> <a href="posts.php?=id<?php echo $row['id']; ?>"> <?php echo $row['title']; ?></a></h2> <p> <?php echo $row['post']; ?></p> <?php } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>View Posts</title> </head> <body> </body> </html> When I run it I get the error : Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\form\posts.php on line 7 How can I fix this?
  23. Thank you! Its successfully adding data to the tables now But is there a reason you did not use a '?>' tag at the end of your first EXAMPLE?
  24. Happy New Year Guys! 366 more days of coding!
×
×
  • 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.