adamjblakey Posted October 31, 2007 Share Posted October 31, 2007 Hi, I seem to be having a problems with this one below that i hope someone can help with. I am trying to create a form that will convert an XML file into SQL. It all works fine apart from one problem below. This is the code: $xml = simplexml_load_file('../database/PropertyInvestment.xml'); foreach ($xml->xpath('/Investments/Investment') AS $property) { $property = array_map('trim', (array)$property); extract($property); mysql_query("INSERT INTO investments (property_id, risk, location1, location2, type1, type2, type3) VALUES ('" . $Property_ID . "', '" . $Risk . "', '" . $property->Locations->Location[0] . "', '" . $property->Locations->Location[1] . "', '" . $property->Types->Type[0] . "', '" . $property->Types->Type[1] . "', '" . $property->Types->Type[2] . "') ") OR die(mysql_error()); } It won't add the values for $property->Types->Type[0], $property->Types->Type[1] etc and just adds a blank entry. Here is an example of the XML <?xml version="1.0" encoding="ISO-8859-2" ?><Investments><Investment><Property_ID>49758</Property_ID><Risk>Medium</Risk><Locations><Location>Coastal</Location></Locations><Types><Type>Buy to let - Tourism</Type><Type>Buy to turn</Type><Type>Low deposit</Type></Types></Investment><Investment><Property_ID>63389</Property_ID><Risk>Medium</Risk><Locations><Location>Rural</Location></Locations><Types><Type>Buy to let - Residential</Type></Types></Investment><Investment><Property_ID>63390</Property_ID><Risk>Low</Risk><Locations><Location>Rural</Location></Locations><Types><Type>High rental yield</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>63548</Property_ID><Risk>Medium</Risk><Locations><Location>Mountain</Location></Locations><Types><Type>Holiday usage</Type></Types></Investment><Investment><Property_ID>63589</Property_ID><Risk>Medium</Risk><Locations><Location>Coastal</Location></Locations><Types><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>64221</Property_ID><Risk>Low</Risk><Locations><Location>Mountain</Location><Location>Rural</Location></Locations><Types><Type>Buy to turn</Type><Type>Capital appreciation</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>64238</Property_ID><Risk>Low</Risk><Locations><Location>Rural</Location></Locations><Types><Type>Buy to turn</Type><Type>Capital appreciation</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment><Property_ID>68956</Property_ID><Risk>Medium</Risk><Locations><Location>Rural</Location></Locations><Types><Type>High rental yield</Type><Type>Holiday usage</Type><Type>Low cost investment</Type></Types></Investment><Investment> Anyone know why this is not working? Cheers in advanced for your help. Link to comment https://forums.phpfreaks.com/topic/75501-converting-xml/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.