0

I'm using this code for my PHP XML pagination.

<?php
$xml = simplexml_load_file('yourxml.xml');

$limit = 5;
$page = $_GET['page'];

foreach ( $xml->item as $item ) {
if ( empty($page) ) {
if ( $item->attributes()->page > 0 && $item->attributes()->page <= $page+$limit )
  echo $item->attributes()->title,'<br/>';
} else {
if ( $item->attributes()->page > ($page-1)*$limit && $item->attributes()->page <= (($page-  1)*$limit)+$limit )    
echo $item->attributes()->title,'<br/>';
}
}
?>

The problem is that it uses foreach loop to read the elements of the XML file. Making the page 1 attribute the first to show up instead of the last page number. I need to show the XML file from last page to the page 1, instead of page 1 to the last page. How could I achieve this? This is to show the most recent entry entered from the XML.

user874737
  • 469
  • 1
  • 9
  • 24
  • I used a for loop instead. for($i=$pagecount;$i>=0;$i--) Then the call to xml elements, $xml->replay[$i-1]->date The problem is now the pagination when page is equal to 1 or something. – user874737 Aug 20 '11 at 11:30
  • 1
    Any solution for this yet? If you sorted yourself out user874737 then pls post the solution for us that need it. Thank you! – Daydah Jun 26 '12 at 10:40

0 Answers0