this is the code I am using include 'SimpleDOM.php';
$xml = simpledom_load_file("data.xml"); $dateformat = "D j M, g:ia";
foreach($xml->sortedXPath('CatchUp[ProgrammeName="MTV"]', 'TransmissionDate') as $i => $item) { if ($i == 4) { // I assume you only want the first 4 break; } print "<p>Programme Name:<strong> " . $item->ProgrammeName. "</strong></p>"; print "<p>Date Shown:<strong> " . date($dateformat, strtotime($item->TransmissionDate)). "</strong></p>"; print "<p>Description:<strong> " . trunc($item->ShortSynopsis,30, " ")."</strong></p>"; print "<p><a href='". $item->VideoID. "'>". $item->VideoID."</a></p>"; } how change the sortXpath mechnanism to sort decsending rather than ascending, so the newest transmission dates should show the first 4.
instead I get the first 4 oldest transmission dates shown first.
Not sure if this is a bug
- data.xml 10.97KB
Comment #1
Posted on Dec 10, 2009 by Swift HippoWhen posting issues, please reduce the code to a minimum and ensure it can be run
"as-this." For instance, PHP doesn't have a trunc()
function, nor is it relevant
to sorting, so this part should be left out.
sortedXPath()
accepts the same arguments as PHP's own [http://docs.php.net/manual/
en/function.array-multisort.php array_multisort()
]
You can sort by descending value with SORT_DESC
{{{
$xml->sortedXPath('CatchUp[ProgrammeName="MTV"]', 'TransmissionDate', SORT_DESC)
}}}
Comment #2
Posted on Dec 10, 2009 by Swift Hippo(No comment was entered for this change.)
Status: Done
Labels:
Type-Other
Priority-Medium