laPistola Posted April 26, 2010 Share Posted April 26, 2010 Hello im trying to quickly populate a DB with locations in a XML file (there are over 45000 locations). The trouble im having is a condition that filters so only a certain type will be inserted into the DB. The code: <?php include_once('../Connections/qwork.php'); $xml = simplexml_load_file('locations-BB.xml'); for($i=0; $i < 10; $i++) { // currently set at 10 to not take time processing all 45k while testing this script $type = $xml->Option[$i]->Type; // when i echo this it prints place if($type=="place") { $locsArr = array('39493','40533','40643','41110'); $sid = NULL; if(in_array($xml->Option[$i]->ParentValue,$locsArr)) { $sid = 1; } mysql_select_db($database_qwork, $qwork); $sql = "INSERT INTO `cities` (`sid`,`bbid`,`city`) VALUES('".$sid."','".$xml->Option[$i]->Value."','".$xml->Option[$i]->Name."')"; // mysql_query($sql, $qwork) or die(mysql_error()); echo $type." "; // just for testing to see if the script passed the first condition } } ?> now its prints place if i echo the $type var i thought trying to force $type into a string (which it should already be) but no look? thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/ Share on other sites More sharing options...
laPistola Posted April 26, 2010 Author Share Posted April 26, 2010 The problem area is $type = $xml->Option[$i]->Type; // when i echo this it prints place if($type=="place") { even though $type when echo'd is place it don't see it as a match?? Thanks you in advance Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048980 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 Could I see a snippet of the xml file? Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048981 Share on other sites More sharing options...
laPistola Posted April 26, 2010 Author Share Posted April 26, 2010 Indeed <Option> <Name> Scotia </Name> <Value> 102 </Value> <ParentValue> 101 </ParentValue> <Type> place </Type> </Option> <Option> <Name> Hampton </Name> <Value> 103 </Value> <ParentValue> 101 </ParentValue> <Type> place </Type> </Option> <Option> <Name> Furman </Name> <Value> 104 </Value> <ParentValue> 101 </ParentValue> <Type> place </Type> </Option> Not formatted correctly so hard to follow i find, its from a company i am integrating a site with. Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048986 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 There MAY be whitespace in the string, causing the problem. What happens when you try to do this: if(trim($type) == "place") Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048988 Share on other sites More sharing options...
laPistola Posted April 26, 2010 Author Share Posted April 26, 2010 Strange i check for whitespace about 4 times when echoing $typre but this has worked fine. Thank You very much. Quote Link to comment https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048992 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.