Pagination using xml

I found a thread here that showed how to do pagination with php and xml and I tried to use it on my page which worked fine other than that…oh yea, I’m new to both php and xml.

Anyway I have no Idea what I’m doing but was hoping someone could help. I get no error messages, I know the problme is with my if statements.

 
 <?php
//read from bev.xml
$file = 'xml/bev.xml';
$xml = simplexml_load_file($file);
 
$limit = 5;
$page = $_GET['page'];

//code displays xml last first
//which is one of the confusing things
//because the pagination sample did not
$i = count($xml->messages)-1; 
for($x=$i;$x>=0;$x--)
if (empty($page) ) 
{
 if ($i > 0 && $i <= $limit)
 { //reformat date from xx/xx/xxxx to month dd, YYYY
  $string = $xml->messages[$x]->vdate;
  $stringArray = explode("/", $string);
  $mydate = mktime(0,0,0,$stringArray[0],$stringArray[1],$stringArray[2]); 
  $converteddate = date("F j, Y", $mydate);
  
  //write to page
  echo
    $converteddate.'<br /><p>'
   .$xml->messages[$x]->msgpost.'<hr></p>';
 }
}
else
{
 if ($i < ($page +1) * $limit && $i <= ($page) + $limit)
    {
     if ($i > 0 && $i <= $limit)
  { //reformat date
   $string = $xml->messages[$x]->vdate;
   $stringArray = explode("/", $string);
   $mydate = mktime(0,0,0,$stringArray[0],$stringArray[1],$stringArray[2]); 
   $converteddate = date("F j, Y", $mydate);
  
   //write to page
   echo
     $converteddate.'<br /><p>'
    .$xml->messages[$x]->msgpost.'<hr></p>';
      }
    }
 }
?>

my xml

 
<messages>
  <mymessage>
    <vdate>mm/dd/yyyy</vdate>
    <msgpost>something bev writes</msgpost>
  </mymessage>
</messages>

HELP!