Jump to content

Nieeru

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Nieeru's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey there! Still very new to these forums. I'm creating a script that reads an external XML file, populating a database and then returning results. I know that I can just read the XML file, loop it through foreach with pre-defined variables outside and then preform the checks, like this: $var1 = true; $var2 = true; foreach($xml->info->members as $member) { if(empty($member['classId'] == 1)) { $var1 = false; } elseif(empty($member['classId'] == 2)) { $var2 = false; } } if(!$var1) { // Do something if it's FALSE } else { // Do something if it's TRUE } ... However, I tried using this logic with MySQL, selecting everything in the database as it only stores the information I need, then checking the query, for so to continue parsing it. I tried using if(empty($data['classId'] == 1)) { $var1 = FALSE; } but it just returns an error while if(mysql_num_rows($data['classId'] == 1) < 1) { $var1 = FALSE; } always returns false, even if the field classId is populated by one or more members. Without having to create seperate queries for every occurance of classId (which for the record are 10 different ID's), I don't really know how to solve this issue. Basically, what I want to do is, select everything from a database, define variables for every class ID as true by default, then loop the returned mysql results and if there are no members within one or more classId's define them as false. I'm not really sure how to work out the logic behind it. I'd really appreciate some help with this.
  2. Hey there. My first post here! Now, I've got this problem trying to solve some logic problem in a foreach loop, while it sounds simple - and I know I've done it before, I can't for the life of me remember how, or re-invent the method of which I did it. What I'm trying to do is to read an external XML file, break it down, and while looping the important fields which holds the data I want to echo, I want to check if a certain condition is met, i.e. if there is a <character ...> child that has classId="1" just to create an example. The problem is, doing this inside the loop will, if there are 100 <character ..> childs, loop the condition 100 times, breaking or halting the if statement inside the loop will halt/break the loop itself. Just checking like this: if($character['classId'] == 1) { .. } else { .. } Won't work either as that checks if all the character fields contain it without having the intended effect. I'm wondering if any of you guys have any idea how to slove this, been sitting at it for a few hours and I can't for the life of me remember how I did it the first time. I'll include the code I've got so far, removing the checks that didn't work. Any help would be greatly appreciated! // Create a basic grabber function.. function grabArmory($url) { // cURL Settings $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); 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'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Execute! $data = curl_exec($ch); // .. And close! curl_close($ch); // Then give us the dataz... return $data; } // The URL to grab. //$url = 'http://eu.wowarmory.com/guild-info.xml?r=Neptulon&gn=Ascendance'; $url = 'http://eu.wowarmory.com/guild-info.xml?r=Doomhammer&gn=rise+against'; // Grab dat data and cache it! $data = grabArmory($url); // Then try and parse it $xml = new SimpleXMLElement($data); // Fetch member count and store it. $memberCount = $xml->guildInfo->guild->members['memberCount']; // Loop all the Guild's members foreach($xml->guildInfo->guild->members->character as $member) { /* Rank 0: Guildmaster 1: Officer 2: Raider 3: Member 4: Trial 5: Alt 6: Community */ // Sort out their Ranking first and foremost! if($member['rank'] == 0) { $member['rank'] = 'Guildmaster'; } elseif($member['rank'] == 1) { $member['rank'] = 'Officer'; } elseif($member['rank'] == 2) { $member['rank'] = 'Raider'; } elseif($member['rank'] == 3) { $member['rank'] = 'Member'; } elseif($member['rank'] == 4) { $member['rank'] = 'Trialist'; } elseif($member['rank'] == 5) { $member['rank'] = 'Alt'; } elseif($member['rank'] == 6) { $member['rank'] = 'Community'; } else { $member['rank'] == 'Unknown'; } /* Sort Genders, Races and Classes by their ID's. 0 = Male 1 = Female 1: Human 1: Warrior 2: Orc 2: Paladin 3: Dwarf 3: Hunter 4: Nightelf 4: Rogue 5: Undead 5: Priest 6: Tauren 6: Death Knight 7: Gnome 7: Shaman 8: Troll 8: Mage 10: Blood Elf 9: Warlock 11: Draenei 11: Druid */ if($member['classId'] == 1) { // Warriors } elseif($member['classId'] == 2) { // Paladins } elseif($member['classId'] == 3) { // Hunters } elseif($member['classId'] == 4) { // Rogues } elseif($member['classId'] == 5) { // Priests } elseif($member['classId'] == 6) { // Death Knights } elseif($member['classId'] == 7) { // Shamans } elseif($member['classId'] == { // Mages } elseif($member['classId'] == 9) { // Warlocks{ } else { // Druids } }
×
×
  • 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.