struktura bi trebala da izgleda ovako
<response>
<books>
<match></match>
<number_of_matches></number_of_matches>
<book>
<title/>
<author/>
<year/>
<jos dodatni elementi/>
</book>
</books>
</response>
a struktura koja se dobija je ovakva:
<response>
<books>
<match></match>
<number_of_matches></number_of_matches>
</books>
</response>
dakle sve sto je unutar foreach petlje nedostaje, probao sam svasta i citao dokumentacju na netu pre nego sto sam postavio pitanje
mozda je ocigledno ali ja ne vidim
nadam se da neko od vas gurua ima resenje mog problema
<?php
$books = array();
$total_books=4;
$m=0;
$titles=array(array('ovde','su','elementi','niza')
array('ovde','su','elementi','niza')); //izbrisao sam podatke mnogo su kabasti, oko ovog niza je sve jasno
$titleValue=$_GET['titleValue'];
for($i=0;$i<$total_books;$i++){
if(strcasecmp($titleValue,$titles[$i][0])==0) {
$book_title=$titles[$i][0];
$book_price_us=$titles[$i][1];
$book_price_uk=$titles[$i][2];
$book_isbn=$titles[$i][3];
$book_author=$titles[$i][4];
$book_year=$titles[$i][5];
$book_discount=$titles[$i][6];
$book_category=$titles[$i][7];
$book_description=$titles[$i][8];
$book_image=$titles[$i][9];
$books [] = array('title' => $book_title,
'USprice' => $book_price_us,
'UKprice' => $book_price_uk,
'isbn' => $book_isbn,
'author' => $book_author,
'year' => $book_year,
'discount' => $book_discount,
'category' => $book_category,
'description' => $book_description,
'image' => $book_image);
$m++;
}
}
if($book_title==""){
$query_match='0';
}
else
$query_match='1';
header('Content-Type: text/xml');
$dom=new DOMDocument();
$response=$dom->createElement('response');//root
$dom->appendChild($response);
$books=$dom->createElement("books");
$response->appendChild($books);
foreach( $books as $book )
{
$b = $dom->createElement( "book" );
$title = $dom->createElement( 'title' );
$title->appendChild(
$dom->createTextNode( $book['title'] )
);
$b->appendChild( $title );
$USprice = $dom->createElement( "USprice" );
$USprice->appendChild(
$dom->createTextNode( $book['USprice'] )
);
$b->appendChild( $USprice );
$UKprice = $dom->createElement( "UKprice" );
$UKprice->appendChild(
$dom->createTextNode( $book['UKprice'] )
);
$b->appendChild( $UKprice );
$isbn = $dom->createElement( "isbn" );
$isbn->appendChild(
$dom->createTextNode( $book['isbn'] )
);
$b->appendChild( $isbn );
$author = $dom->createElement( "author" );
$author->appendChild(
$dom->createTextNode( $book['author'] )
);
$b->appendChild( $author );
$year = $dom->createElement( "year" );
$year->appendChild(
$dom->createTextNode( $book['year'] )
);
$b->appendChild( $year );
$discount = $dom->createElement( "discount" );
$discount->appendChild(
$dom->createTextNode( $book['discount'] )
);
$b->appendChild( $discount );
$category = $dom->createElement( "category" );
$category->appendChild(
$dom->createTextNode( $book['category'] )
);
$b->appendChild( $category );
$description = $dom->createElement( "description" );
$description->appendChild(
$dom->createTextNode( $book['description'] )
);
$b->appendChild( $description );
$image = $dom->createElement( "image" );
$image->appendChild(
$dom->createTextNode( $book['image'] )
);
$b->appendChild( $image );
$books->appendChild( $b );
}
$match=$dom->createElement('match');
$matchText=$dom->createTextNode($query_match);
$match->appendChild($matchText);
$number_of_matches=$dom->createElement('number_of_matches');
$number_of_matches_text=$dom->createTextNode($m);
$number_of_matches->appendChild($number_of_matches_text);
$books->appendChild($match);
$books->appendChild($number_of_matches);
$xmlString=$dom->saveXML();
echo $xmlString;
?>