Random sort results
Submitted by filser on Thu, 2010-05-20 18:03.Magic Parser
Hi.
Is it possible to randomly order the items of an XML feed so that each time the XML-feed is fetched the result is differently sorted.
Thanks.
Great ! Works like a charm ! Thanks a lot.
Hi,
What you need to do is instead of displaying each record in myRecordHandler(), add the record to a global array ($records), and then after the parse shuffle the $records array, and display with your original myRecordHandler using a foreach loop. For example:
<?phpfunction myDisplayRecordHandler($record)
{
// exactly as your original myRecordHandler
}
function myRecordHandler($record)
{
global $records;
$records[] = $record;
}
$records = array();
MagicParser_parse("filename.xml","myRecordHandler","xml|FORMAT/STRING/");
shuffle($records);
foreach($records as $record)
{
myDisplayRecordHandler($record):
}
?>
Hope this helps!
Cheers,
David.