Hello
Like many others I've been creating a simple PHP/XML CMS with a wonderful tutorial on this site. Essentially it's a 'latest news' page. The stories display on the web page with the most recent item created at the top, but I want to be able to 're-shuffle' the stories based on a number I add to an XML node.
I'm sure there must be a way with PHP to order the results based on a number in one of the nodes? For example:
In the above example, because it has been given the rank '1', I would like it to display first on the web page no matter when it was created. Other stories with higher numbers would appear below it. Does that make sense?!Code:<?xml version="1.0"?> <article id="March"> <headline>The Headline</headline> <rank>1</rank> <email></email> <abstract>A brief description here.</abstract> <keywords></keywords> <status>live</status> <para-intro>Some text here. </para-intro> </article>
Here is the php code that extracts the info and displays it on the web page:
Any help or advice would be much appreciated!PHP Code:<?php
$dh = opendir('./xml/');
$fileCount = 0;
while ($file = readdir($dh) and $fileCount < 40){
if (eregi("^..?$", $file)) {
continue;
}
$open = "./xml/".$file;
$xml = domxml_open_file($open);
//we need to pull out all the things from this file that we will need to
//build our links
$root = $xml->root();
$stat_array = $root->get_elements_by_tagname("status");
$status = extractText($stat_array);
$ab_array = $root->get_elements_by_tagname("abstract");
$abstract = extractText($ab_array);
$h_array = $root->get_elements_by_tagname("headline");
$headline = extractText($h_array);
if ($status != "live"){
continue;
}
echo "<tr><td>";
echo stripslashes ("<a href=\"showArticle.php?file=".$file . "\">".$headline . "</a><br>");
echo stripslashes ("$abstract");
echo "<p> </p></td></tr>";
$fileCount++;
}
?>


Reply With Quote

Bookmarks