sandipan.rcciit 0 Light Poster

hello,

i want to create a program to fetch the xml files data to mysql database.
here is my code

<?php
include 'mysql-connect.php';
$m=1;
$n=".xml";
while($m<6)
{
 $str=$m.$n;
$doc = new DOMDocument();
$doc->load( $str );
$params = $doc->getElementsByTagName('BookData'); // Find BookData
$k=0;
foreach ($params as $param) //go to each section 1 by 1
{
		 $isbn= $params->item($k)->getAttribute('isbn');
		 $issbn13= $params->item($k)->getAttribute('isbn13');
		           
         $Title1 = $params->item($k)->getElementsByTagName('Title'); 
		 $title=$Title1->item($j)->nodeValue;
		 
		 $TitleLong2 = $params->item($k)->getElementsByTagName('TitleLong'); 
		 $titlelong=$TitleLong2->item($j)->nodeValue;
		$TitleLong3 = $params->item($k)->getElementsByTagName('AuthorsText'); 
		 $author=$TitleLong3->item($j)->nodeValue;
		 
		 $params3 = $params->item($k)->getElementsByTagName('PublisherText');
         $i=0; 
         foreach ($params3 as $p) 
	{
           $publisher=$params3->item($i)->nodeValue; //get Node value ;
                              $i++;  
                   }  
				   
 mysql_query("INSERT INTO books_data_master (ISBN,ISBN13,Title_Short,Title_Long,Authors_Name,Publisher,Category_Code) 
VALUES('$isbn','$issbn13','$title','$titlelong','$author','$publisher',15)");
echo  $isbn;
echo"<br>";
echo  $issbn13;
echo"<br>";
echo  $title;
echo"<br>";
echo  $titlelong;
echo"<br>";
echo  $author;
echo"<br>";
echo  $publisher;
echo"<br>";
         $k++;
      }
	  
	  $m++;
}
?>

problem is it displays all the values from the various xml files but insert only the 1st and last xml file value to database in mysql.

here is my database structure:

CREATE TABLE `books_data_master` (
  `Book_ID` int(50) NOT NULL auto_increment,
  `ISBN` varchar(50) collate ascii_bin NOT NULL,
  `ISBN13` varchar(50) collate ascii_bin NOT NULL,
  `Title_Short` varchar(100) collate ascii_bin NOT NULL,
  `Title_Long` varchar(200) collate ascii_bin NOT NULL,
  `Authors_Name` varchar(100) collate ascii_bin NOT NULL,
  `Publisher` varchar(200) collate ascii_bin NOT NULL,
  `Category_Code` varchar(10) collate ascii_bin NOT NULL,
  UNIQUE KEY `Book-ID` (`Book_ID`,`ISBN`)
) ENGINE=MyISAM  DEFAULT CHARSET=ascii COLLATE=ascii_bin COMMENT='Books Data' AUTO_INCREMENT=3 ;

i dont identify the problem. plz help me.

there is my sample xml files name as 1.xml:

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2009-07-21T05:02:43Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="die_oper_im_17_jahrhundert" isbn="3890071341" isbn13="9783890071343">
<Title>Die Oper im 17. Jahrhundert</Title>
<TitleLong></TitleLong>
<AuthorsText>Silke Leopold</AuthorsText>
<PublisherText publisher_id="laaber">Laaber : Laaber, c2004.</PublisherText>
</BookData>
</BookList>
</ISBNdb>

there is my sample xml files name as 2.xml:

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2009-07-21T05:02:44Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="don_giovanni_in_musica" isbn="8831754750" isbn13="9788831754750">
<Title>Don Giovanni in musica</Title>
<TitleLong>Don Giovanni in musica: dall'"Empio punito" a Mozart</TitleLong>
<AuthorsText>Nino Pirrotta</AuthorsText>
<PublisherText publisher_id="marsilio">Venezia : Marsilio, c1991.</PublisherText>
</BookData>
</BookList>
</ISBNdb>

3.xml:

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2009-07-21T05:02:46Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="don_giovannis_progress" isbn="0941419940" isbn13="9780941419949">
<Title>Don Giovanni's progress</Title>
<TitleLong>Don Giovanni's progress: a rake goes to the opera</TitleLong>
<AuthorsText>Nino Pirrotta; translated by Harris S. Saunders, Jr</AuthorsText>
<PublisherText publisher_id="marsilio">New York : Marsilio, [c1994].</PublisherText>
</BookData>
</BookList>
</ISBNdb>

4.xml:

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2009-07-21T05:02:47Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="don_giovannis_progress_a01" isbn="0941419711" isbn13="9780941419710">
<Title>Don Giovanni's progress</Title>
<TitleLong>Don Giovanni's progress: a rake goes to the opera</TitleLong>
<AuthorsText>Nino Pirrotta; translated by Harris S. Saunders, Jr</AuthorsText>
<PublisherText publisher_id="marsilio">New York : Marsilio, [c1994].</PublisherText>
</BookData>
</BookList>
</ISBNdb>

5.xml:

<?xml version="1.0" encoding="UTF-8"?>

<ISBNdb server_time="2009-07-21T05:02:48Z">
<BookList total_results="1" page_size="10" page_number="1" shown_results="1">
<BookData book_id="studien_zur_barockoper" isbn="3921029570" isbn13="9783921029572">
<Title>Studien zur Barockoper</Title>
<TitleLong></TitleLong>
<AuthorsText>hrsg. von Constantin Floros, Hans Joachim Marx und Peter Petersen</AuthorsText>
<PublisherText publisher_id="verlag_der_musikalienhandlung">Hamburg : Verlag der Musikalienhandlung, c1978.</PublisherText>
</BookData>
</BookList>
</ISBNdb>

now i am working with just 5 xml files given above.
plz help me to resolve the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.