innitboy Posted December 4, 2006 Share Posted December 4, 2006 This script turns all the xml tags into arrays and inputs the relevant data into the field names in my tableI cant get it to loop over each result (or top level tag),It only shows and imports the last result in the resultsetWould appreciate any help?[code]<?php include 'library/config.php'; include 'library/opendb.php';$file = "my-xml.xml";$feed = array();$key = "";$info = "";function startElement($xml_parser, $attrs ) { global $feed; }function endElement($xml_parser, $name) { global $feed, $info; $key = $name; $feed[$key] = $info; $info = ""; }function charData($xml_parser, $data ) { global $info; $info .= $data; }$xml_parser = xml_parser_create();xml_set_element_handler($xml_parser, "startElement", "endElement");xml_set_character_data_handler($xml_parser, "charData" );$fp = fopen($file, "r");while ($data = fread($fp, 8192))!xml_parse($xml_parser, $data, feof($fp));xml_parser_free($xml_parser);$sql= "INSERT INTO section ( ";$j=0;$i=count($feed);foreach( $feed as $assoc_index => $value ) { $j++; $sql.= strtolower($assoc_index); if($i>$j) $sql.= " , "; if($i<=$j) {$sql.= " ) VALUES ('";} }$h=0;foreach( $feed as $assoc_index => $value ) { $h++; $sql.= utf8_decode(trim(addslashes($value))); if($i-1>$h) $sql.= "', '"; if($i<=$h) $sql.= "','');"; } $query=trim($sql); echo $value;if (mysql_query($sql)){echo "success in table creation.";} else {echo "no table created.";}echo mysql_error(); echo $sql;?> [/code] Link to comment https://forums.phpfreaks.com/topic/29378-problem-with-xml-mysql-php-import-script/ Share on other sites More sharing options...
innitboy Posted December 4, 2006 Author Share Posted December 4, 2006 am i missing something like this?if ($assoc_index = "my_top_level_tag"){rest of my code} Link to comment https://forums.phpfreaks.com/topic/29378-problem-with-xml-mysql-php-import-script/#findComment-134741 Share on other sites More sharing options...
innitboy Posted December 4, 2006 Author Share Posted December 4, 2006 ok have found out that this piece of code is causing the problem[code] $feed[$key] = $info;[/code]just not sure what to replace it with to get it to show each key rather than the last key in the array. Link to comment https://forums.phpfreaks.com/topic/29378-problem-with-xml-mysql-php-import-script/#findComment-134758 Share on other sites More sharing options...
innitboy Posted December 4, 2006 Author Share Posted December 4, 2006 bump innit Link to comment https://forums.phpfreaks.com/topic/29378-problem-with-xml-mysql-php-import-script/#findComment-134877 Share on other sites More sharing options...
innitboy Posted December 4, 2006 Author Share Posted December 4, 2006 en autre bump Link to comment https://forums.phpfreaks.com/topic/29378-problem-with-xml-mysql-php-import-script/#findComment-135107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.