Question handling xml data


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

I have sucessfull followed this tutorial
http://www.phpfreaks.com/tutorial/handling-xml-data

and used xpath to find the books I need, here is my code

Code: [Select]<?php
// load SimpleXML
$books = new SimpleXMLElement('books.xml', null, true);

echo <<<EOF
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Price at Amazon.com</th>
<th>ISBN</th>
</tr>

EOF;
foreach($books->xpath('book1/book') as $book) // loop through our books
{
echo <<<EOF
<tr>
<td>{$book->title}</td>
<td>{$book->author}</td>
<td>{$book->publisher}</td>
<td>${$book->amazon_price}</td>
<td>{$book['isbn']}</td>
</tr>

EOF;
}
echo '</table>';
?>

now I want to only show the first 5 books in the xml file as it is updated regularly

I can't seem to figure out how to do this.

any help would be great , thanks

No comments posted yet

Your Answer:

Login to answer
321 Like 33 Dislike
Previous forums Next forums
Other forums

Search function
I am looking for some guidance from the experts.

I am trying to create a search function. It

server trace logs
could any one tell me from where do i get error logs in xMII??I want to check the reason for dtabase

matching numbers inside ( )
I know I can match numbers by just [0-9]+, so I thought matching numbers inside ( ) would be somethi

Query failed issue with php script but works fine in mssql manager!
hi i have the script below which copies data from one table to another but will only insert new data

Check before inserting in DB ???
This is my code
---------------
if ( $_POST ['Submit'])
{{
$username = $_POST ['usernm

creating a 1 to 100 in a table
hi guys I am a newb in php need some help.

I have a table with 1 column and 100 rows and in

cURL error
So here is my code... I got it off of here... http://www.youtube.com/watch?v=XcgQUsorF_8
Because

rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded

New to mysqli library - Multiple query problem
Greetings,

I am writing a batch program that executes 3 queries on a single page. Using mysql

Create a form of 2 numbers input and find the greatest.
Hi, everybody.

I have a homework in my training of php, which ask you to make a form that ask

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash