You are here:  » Reverse Sort


Reverse Sort

Submitted by crusnac on Wed, 2012-12-05 00:39 in

I have a simple xml file that I am parsing, but would like to reverse order the entries.

<?php
  $mainURL 
$this->url();
  print 
$mainUrl;
  function 
vimeoChannels($record)
  {
    print 
'<li>';
    print 
'<i class="icon-bookmark"></i> <a ';
    print 
' href="';
    print 
URL_PUBLIC;
    print 
'video/channel/';
    print 
$record["ID"];
    print 
'/">';
    print 
$record["NAME"];
    
$channelname $record["NAME"];
    print 
'</a>';
    print 
'</li>';
  }
  
MagicParser_parse("{link saved}","vimeoChannels","xml|CHANNELS/CHANNEL/");
?>

Submitted by support on Fri, 2012-12-07 10:34

Hi,

The best way to reverse records is to parse the records into an array, reverse the array and then process each array entry using exactly the same record handler function as your existing code. Consider the following example;

<?php
  $mainURL 
$this->url();
  print 
$mainUrl;
  function 
vimeoChannels($record)
  {
    print 
'<li>';
    print 
'<i class="icon-bookmark"></i> <a ';
    print 
' href="';
    print 
URL_PUBLIC;
    print 
'video/channel/';
    print 
$record["ID"];
    print 
'/">';
    print 
$record["NAME"];
    
$channelname $record["NAME"];
    print 
'</a>';
    print 
'</li>';
  }
  
$records = array();
  function 
myRecordHandler($record)
  {
    global 
$records;
    
$records[] = $record;
  }
  
MagicParser_parse("{link saved}","myRecordHandler","xml|CHANNELS/CHANNEL/");
  
$records array_revers($records);
  foreach(
$records as $record)
  {
    
vimeoChannels($record);
  }
?>

Hope this helps!
Cheers,
David
--
MagicParser.com