You are here:  » Sort feild records into order


Sort feild records into order

Submitted by tbbd2007 on Fri, 2007-08-24 19:03 in

I have several feeds that are based on charts, i.e. 1-100 most popular albums. Having imported the feeds I can see that the albums are in a random order, how do I sort them into numerical order of 1-100. The chart position is the first few characters of the title field. If you can provide code to fit in with my existing code of "

<?php
  
require("MagicParser.php");
  
// get the current page and total from the URL
  
$page $_GET["page"];
  
$total $_GET["total"];
  
// if not set, force to page 1
  
if (!$page$page 1;
  
// count the records if not in URL
  
function myRecordCountHandler($record)
  {
    global 
$total;
    
$total++;
  }
  if (!
$total)
  {
    
MagicParser_parse("http://www.xxxxx.com/xxxxx.xml","myRecordCountHandler","xml|products/product/");
  }
  
// reset counter, and define number of items wanted on each page
  
$counter 0;
  
$itemsOnPage 25;
  function 
myRecordHandler($record)
  {
    global 
$page;
    global 
$counter;
    global 
$itemsOnPage;
    
// increment counter
    
$counter++;
    
// don't display while looping through items on previous pages
    
if ($counter < (($page-1)*$itemsOnPage)) return FALSE;
    
// stop parsing if already displayed maxium number of items per page
    
if ($counter == ($page*$itemsOnPage)) return TRUE;
    
// display record as normal
    
print "<table>";
    print 
"<tr><td rowspan='3' valign='top'><a href='".$record["PRODUCTURL"]."' target='_blank'><img src=".$record["IMAGEURL"]." border='0' width='50' valign='top'></a></td><td><a href='".$record["PRODUCTURL"]."' target='_blank'>".$record["NAME"]."</a></td></tr>";
    print 
"<tr><td><p align='justify'>".$record["DESCRIPTION"]."</p></td></tr>";
    print 
"<tr><td class='red'>&pound;".$record["PRICE"]."</td></tr>";
    print 
"</table>";
    print 
"<br />";
  }
  
MagicParser_parse("http://www.xxxxx.com/xxxxx.xml","myRecordHandler","xml|products/product/");
  
// finally display next and previous links
  
if ($page 1)
  {
    print 
"<p><a href='?total=".$total."&page=".($page-1)."'>Previous page</a></p>";
  }
  if (
$counter $total)
  {
    print 
"<p><a href='?total=".$total."&page=".($page+1)."'>Next page</a></p>";
  }
?>
" it would be most appreciated.

Thanks

Stephen

Submitted by support on Fri, 2007-08-24 19:09

Hi Stephen,

This is complicated by the fact that you are using paging code to display the records in blocks of 25 instead of all on the same page.

It should be possible - the trick is basically to read into an array, with the key value being the chart position, and then sorting that array. You then display records from the array instead of within myRecordHandler.

To work it out I would need to have a look at the XML for you. Can you email me a sample of the XML that you download from your source URL? Reply to your reg code or forum registration email is the easiest way to get me - and i'll take a look and put together an example for you!

Cheers,
David.