Deathwillow Posted April 23, 2009 Share Posted April 23, 2009 So a brief description on what this script does so everyone knows what I'm attempting followed by the problem I am currently having. What it does: Basically what this script does is pull my guilds information from a website, www.wowarmory.com, and then pulls each characters specific information and places it all in arrays of different sorts. Once all the arrays are complete it then places it into my database for later use by myself. I currently have it updating once a day as you can only pull so much information from the website before it puts a 12 hour block on you. <?php /////////////////////////////////////////////// // Gets guild list from www.wowarmory.com // ///////////////////////////////////////////// $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.wowarmory.com/guild-info.xml?r=Gorgonnash&n=Midnight%20Reveries&p=1"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); $armory = curl_exec($ch); curl_close($ch); print_r($armory); /////////////////////////////// // Open 2 new DOMDocuments // ///////////////////////////// $doc = new DOMDocument(); $doc->loadXML($armory); $doc2 = new DOMDocument(); /////////////////////////////// // Connects to database // ///////////////////////////// $connection = mysql_connect("server", "username", "password") or die(mysql_error()); $connection = mysql_select_db("database name") or die(mysql_error()); /////////////////////////////////////// // truncate the wow_character table // ///////////////////////////////////// $refresh = ("TRUNCATE TABLE wow_character"); mysql_query($refresh); /////////////////////////////////////////////////////////////////////////////////// // Checks database for character, if exists updates them, if not adds them. // ///////////////////////////////////////////////////////////////////////////////// $memberList = $doc->getElementsByTagName("character"); foreach($memberList as $toon) { $data = array( 'NAME' => $toon->getAttribute("name"), 'RACEID' => $toon->getAttribute("raceId"), 'LEVEL' => $toon->getAttribute("level"), 'CLASSID' => $toon->getAttribute("classId"), 'GENDERID' => $toon->getAttribute("genderId"), 'RANK' => $toon->getAttribute("rank"), 'ACHPOINT' => $toon->getAttribute("achPoints"), ); $temp = "http://www.wowarmory.com/character-sheet.xml?r=Gorgonnash&n=" . $data['NAME']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $temp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); $uArmory = curl_exec($ch); curl_close($ch); $doc2->loadXML($uArmory); $x = 1; $userArmory = $doc2->getElementsByTagName("talentSpec"); foreach ($userArmory as $toon2) { if ($x == 1) { $spec1 = array( 'TREE1' => $toon2->getAttribute('treeOne'), 'TREE2' => $toon2->getAttribute('treeTwo'), 'TREE3' => $toon2->getAttribute('treeThree'), 'ICON' => $toon2->getAttribute('icon'), 'PRIM' => $toon2->getAttribute('prim'), 'ACTIVE' => '', ); if ($toon2->getAttribute('active') == 1) { $spec1['ACTIVE'] = 1; } } elseif ($x == 2) { $spec2 = array( 'TREE1' => $toon2->getAttribute('treeOne'), 'TREE2' => $toon2->getAttribute('treeTwo'), 'TREE3' => $toon2->getAttribute('treeThree'), 'ICON' => $toon2->getAttribute('icon'), 'PRIM' => $toon2->getAttribute('prim'), 'ACTIVE' => '', ); if ($toon2->getAttribute('active') == 1) { $spec2['ACTIVE'] = 1; } } else { echo "To many talent trees"; } $x++; } $x = 1; $userArmory = $doc2->getElementsByTagName("skill"); foreach ($userArmory as $toon2) { if ($x == 1) { $prof1 = array( 'PROF' => $toon2->getAttribute("name"), 'LEVEL' => $toon2->getAttribute("value"), 'MAX' => $toon2->getAttribute("max"), ); } elseif ($x == 2) { $prof2 = array( 'PROF' => $toon2->getAttribute("name"), 'LEVEL' => $toon2->getAttribute("value"), 'MAX' => $toon2->getAttribute("max"), ); } else { echo "To many professions?"; } $x++; } $userArmory = $doc2->getElementsByTagName("lifetimehonorablekills"); foreach ($userArmory as $toon2) { $hkills = $toon2->getAttribute("value"); } $sql_check = "SELECT * FROM wow_character WHERE NAME = '" . $data['NAME'] . "' LIMIT 1"; $res_check = mysql_query($sql_check); //if (mysql_num_rows($res_check) == 1) //{ // $row = mysql_fetch_array($res_check); // $sql_update = "UPDATE wow_character SET LEVEL='" . $data['LEVEL'] . "', GENDERID='" . $data['GENDERID'] . "', ACHPOINTS='" . $data['ACHPOINT'] . "', RANK='" . $data['RANK'] . "', HKILLS='" . $hkills . "', PROF_1='" . $prof1['PROF'] . "', PROF_1_VALUE='" . $prof1['LEVEL'] . "', PROF_1_MAX='" . $prof1['MAX'] . "', PROF_2='" . $prof2['PROF'] . "', PROF_2_VALUE='" . $prof2['LEVEL'] . "', PROF_2_MAX='" . $prof2['MAX'] . "', TALENT1TREE_1='" . $spec1['TREE1'] . "', TALENT1TREE_2='" . $spec1['TREE2'] . "', TALENT1TREE_3='" . $spec1['TREE3'] . "', TALENT1TREE_A='" . $spec1['ACTIVE'] . "', TALENT1PRIM='" . $spec1['PRIM'] . "', TALENT1ICON='" . $spec1['ICON'] . "', TALENT2TREE_1='" . $spec2['TREE1'] . "', TALENT2TREE_2='" . $spec2['TREE2'] . "', TALENT2TREE_3='" . $spec2['TREE3'] . "', TALENT2TREE_A='" . $spec2['ACTIVE'] . "', TALENT2PRIM='" . $spec2['PRIM'] . "', TALENT2ICON='" . $spec2['ICON'] . "' WHERE ID='" . $row['ID'] . "' LIMIT 1 "; // $sql = mysql_query($sql_update); //} else { $sql_insert = "INSERT INTO wow_character (NAME, LEVEL, CLASSID, ACHPOINTS, GENDERID, RACEID, RANK, HKILLS, PROF_1, PROF_1_VALUE, PROF_1_MAX, PROF_2, PROF_2_VALUE, PROF_2_MAX, TALENT1TREE_1, TALENT1TREE_2, TALENT1TREE_3, TALENT1TREE_A, TALENT1PRIM, TALENT1ICON, TALENT2TREE_1, TALENT2TREE_2, TALENT2TREE_3, TALENT2TREE_A, TALENT2PRIM, TALENT2ICON) VALUES ( '" . $data['NAME'] . "', '" . $data['LEVEL'] . "', '" . $data['CLASSID'] . "', '" . $data['ACHPOINT'] . "', '" . $data['GENDERID'] . "', '" . $data['RACEID'] . "', '" . $data['RANK'] . "', '" . $hkills . "', '" . $prof1['PROF'] . "', '" . $prof1['LEVEL'] . "', '" . $prof1['MAX'] . "', '" . $prof2['PROF'] . "', '" . $prof2['LEVEL'] . "', '" . $prof2['MAX'] . "', '" . $spec1['TREE1'] . "', '" . $spec1['TREE2'] . "', '" . $spec1['TREE3'] . "', '" . $spec1['ACTIVE'] . "', '" . $spec1['PRIM'] . "', '" . $spec1['ICON'] . "', '" . $spec2['TREE1'] . "', '" . $spec2['TREE2'] . "', '" . $spec2['TREE3'] . "', '" . $spec2['ACTIVE'] . "', '" . $spec2['PRIM'] . "', '" . $spec2['ICON'] . "' )"; $sql = mysql_query($sql_insert); sleep(3); $spec1 = array(); $spec2 = array(); $data = array(); $prof1 = array(); $prof2 = array(); } /////////////////////////// // Close connection. // ///////////////////////// echo "Database updated."; mysql_close($connection); ?> What the problem is: Quite simply it seems to be dropping random numbers of characters specs and professions. Their isn't a rhyme or reason as to why from what I can tell. My closest guess would be it might be clearing the array before it enter the database? but the counter to that is why is it only doing it for the specs and not the other information such as name/race/class etc. My guess as to where my problem might be is somewhere in this section of the code: $x = 1; $userArmory = $doc2->getElementsByTagName("talentSpec"); foreach ($userArmory as $toon2) { if ($x == 1) { $spec1 = array( 'TREE1' => $toon2->getAttribute('treeOne'), 'TREE2' => $toon2->getAttribute('treeTwo'), 'TREE3' => $toon2->getAttribute('treeThree'), 'ICON' => $toon2->getAttribute('icon'), 'PRIM' => $toon2->getAttribute('prim'), 'ACTIVE' => '', ); if ($toon2->getAttribute('active') == 1) { $spec1['ACTIVE'] = 1; } } elseif ($x == 2) { $spec2 = array( 'TREE1' => $toon2->getAttribute('treeOne'), 'TREE2' => $toon2->getAttribute('treeTwo'), 'TREE3' => $toon2->getAttribute('treeThree'), 'ICON' => $toon2->getAttribute('icon'), 'PRIM' => $toon2->getAttribute('prim'), 'ACTIVE' => '', ); if ($toon2->getAttribute('active') == 1) { $spec2['ACTIVE'] = 1; } } else { echo "To many talent trees"; } $x++; } $x = 1; $userArmory = $doc2->getElementsByTagName("skill"); foreach ($userArmory as $toon2) { if ($x == 1) { $prof1 = array( 'PROF' => $toon2->getAttribute("name"), 'LEVEL' => $toon2->getAttribute("value"), 'MAX' => $toon2->getAttribute("max"), ); } elseif ($x == 2) { $prof2 = array( 'PROF' => $toon2->getAttribute("name"), 'LEVEL' => $toon2->getAttribute("value"), 'MAX' => $toon2->getAttribute("max"), ); } else { echo "To many professions?"; } $x++; } If you need more information on what I'm attempting to do or why I wrote the code this way please ask, I tried to explain the problem as best I could, but if I wasn't clear enough please ask and I'll attempt to explain it a little better. Quote Link to comment Share on other sites More sharing options...
radi8 Posted April 23, 2009 Share Posted April 23, 2009 How do you know that the spec/talents are being dropped... are you not seeing them in the database? Or are yoiu seeing it skipp items some other way? How are you doing your debugging? Is there a way to only get 1 or 2 names from the wow db? If so, grab only 1 or 2 guild toons to process and do some echo's to see what dumps out (to get the array, do a print <pre>echo toon2 </pre>) You will be able to see where it is breaking at that point. Quote Link to comment Share on other sites More sharing options...
Deathwillow Posted April 23, 2009 Author Share Posted April 23, 2009 How do you know that the spec/talents are being dropped... are you not seeing them in the database? Or are yoiu seeing it skipp items some other way? How are you doing your debugging? Is there a way to only get 1 or 2 names from the wow db? If so, grab only 1 or 2 guild toons to process and do some echo's to see what dumps out (to get the array, do a print <pre>echo toon2 </pre>) You will be able to see where it is breaking at that point. Well, they are the only 2 that aren't added to the database randomly. As far as debugging I'm not doing really anything simply because it's only happening in those 2 areas and always at the same time. For instance: -it'll get 5 people corrently -skip 1 persons professions and talents only -get another 15 right -skip 4 people's professions and talents only etc etc So the problem has to lie within that area of the code... the only thing that comes to mind is use a different counter for each loop... although honestly that shouldn't be a serious issue. It's really odd. Quote Link to comment Share on other sites More sharing options...
Deathwillow Posted April 23, 2009 Author Share Posted April 23, 2009 Is there a way to get a array variable that increases during each loop? example: $spec[1] = array(); $spec[2] = array(); where 1 & 2 is a variable that increases? Quote Link to comment Share on other sites More sharing options...
radi8 Posted April 23, 2009 Share Posted April 23, 2009 Sure, 1 way is: for($i=1;$i<=2;$i++){ $spec[$i] = array( => $toon2->getAttribute('treeOne'), => $toon2->getAttribute('treeTwo'), => $toon2->getAttribute('treeThree'), => $toon2->getAttribute('icon'), => $toon2->getAttribute('prim'), => ( $toon2->getAttribute('active') == 1 ) ? 1 : 0; } do same for talents Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.