Highlord Posted August 30, 2006 Share Posted August 30, 2006 Ok, I have a XML-file with the following structure: <row><field name="id">12</field><field name="car">VW</field><field name="year">1992</field><field name="type">4x4</field><field name="fuel">Gas</field></row>Offcourse with multipe <row>'s. Now I have to write a PHP-script that gets the id, car, and type out of this structure and assigns it to a variable so i can put this in sql-database table (carid, carname, type).I allready found a way to show the data I want on the screen, I just cant figure out how i get it in the database. This is how I print the selected data on a screen: <?php $mblist = ''; $flag = false; $type = 0; $hgid = array(); $normid= array(); $perc_code = array(); function openElement($parser, $element, $attributes) { global $flag; if (($element == 'field') && ($attributes['name'] == 'id')) { $flag = true; $type = 1; } if (($element == 'field') && ($attributes['name'] == 'car')) { $flag = true; $type = 2; } if (($element == 'field') && ($attributes['name'] == 'type')) { $flag = true; $type = 3; } } function closeElement($parser, $element) { global $flag; $flag = false; } function characterData($parser, $data) { global $flag,$mblist; if ($flag) $mblist[] = $data; } $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); xml_set_element_handler($parser, "openElement", "closeElement"); xml_set_character_data_handler($parser, "characterData"); $document = file_get_contents("lassi.xml"); xml_parse($parser, $document); xml_parser_free($parser); foreach ($mblist as $value) { echo $value.'<br/>'; }?>I'd realy like some actual help with the scripting and not so much a link to a site or anything, because I've been trying to do this for 2days now and I think I've read every possible site about it, but just dont find how to do it :( Quote Link to comment https://forums.phpfreaks.com/topic/19118-php-getting-data-out-of-an-xml-file-and-write-it-to-sql-database/ Share on other sites More sharing options...
ober Posted August 30, 2006 Share Posted August 30, 2006 When you run the foreach loop... what does it print out? Quote Link to comment https://forums.phpfreaks.com/topic/19118-php-getting-data-out-of-an-xml-file-and-write-it-to-sql-database/#findComment-82772 Share on other sites More sharing options...
Highlord Posted August 30, 2006 Author Share Posted August 30, 2006 In this example it prints out:12VW4x4 Quote Link to comment https://forums.phpfreaks.com/topic/19118-php-getting-data-out-of-an-xml-file-and-write-it-to-sql-database/#findComment-82783 Share on other sites More sharing options...
Highlord Posted August 30, 2006 Author Share Posted August 30, 2006 Nobody? :( Quote Link to comment https://forums.phpfreaks.com/topic/19118-php-getting-data-out-of-an-xml-file-and-write-it-to-sql-database/#findComment-82847 Share on other sites More sharing options...
Highlord Posted August 31, 2006 Author Share Posted August 31, 2006 Going to bump this one last time, hope someone realy has a solution to this. Quote Link to comment https://forums.phpfreaks.com/topic/19118-php-getting-data-out-of-an-xml-file-and-write-it-to-sql-database/#findComment-83344 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.