Jump to content

XML condition


laPistola

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/199839-xml-condition/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/199839-xml-condition/#findComment-1048986
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.