0

i have the following xml file.how to display the first tag (tag by tag) then when next button are click the second tag is display


<?xml version="1.0"?>
<records>
<reg >
<name>hari</name>
<age>22</age>
<mark>67</mark>

</reg>
</records>
<records>
<reg >
<name>hari</name>
<age>20</age>
<mark>78</mark>

</reg>
</reg>
<reg>
<book >
<name>hari</name>
<age>21</age>
<mark>88</mark>

</reg>
</records>

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by DanielTulp
0

to display data from an xml check out these resources
http://www.w3schools.com/PHP/php_xml_simplexml.asp
http://php.net/manual/en/book.xml.php

here is some sample code I use to display text (used on http://photo.danieltulp.nl)

<?php
                $newsitems = new SimpleXMLElement('xmlfilename.xml', null, true);

                foreach ($newsitems as $item):?>
                <div class="newsitem">
                    <h4><?php echo $item->title?><span class="date"><?php echo $item->date?></span></h4>                    
                    <p><?php echo $item->body?></p>
                </div>
                <?php 
                endforeach;?>

if you want a button to go the next record, you could use:

<?php
                $records = new SimpleXMLElement('records.xml', null, true);
                $i = 0;
                foreach ($records as $record):?>
                <div class="record-<?php echo $i;?>" style="display:none;">
                    <p>Name: <?php echo $record->name?><br />
                    Age: <?php echo $record->age?><br />                   
                    Mark: <?php echo $record->mark?></p>
                </div>
                $i = $i + 1;
                <?php endforeach;?>

and then use javascript to set the display property to block or inline

Edited by DanielTulp: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.