Or should I just use MySQL to rewrite the data to a table each time the page loads?
Currently, my Parse code is
<?php
class RSSParser {
var $insideitem = false;
var $tag = "";
var $ServerName = "";
var $ServerStatus = "";
var $ServerType = "";
var $ServerPopulation = "";
function startElement($parser, $tagName, $attrs) {
if ($this->insideitem) {
$this->tag = $tagName;
} elseif ($tagName == "SERVER") {
$this->insideitem = true;
while (list ($key, $val) = each($attrs)) {
switch ($key) {
case "NAME":
$this->ServerName .= $val;
break;
case "TYPE":
$this->ServerType .= $val;
break;
}
}
}
}
function endElement($parser, $tagName) {
if ($tagName == "SERVER") {
printf("<tr>\n");
if ($this->ServerType) {
printf("<td>%s <i>(%s)</i></td>\n", $this->ServerName, $this->ServerType);
} else {
printf("<td>%s</td>\n", $this->ServerName);
}
if ($this->ServerPopulation > 0) {
printf("<td>%s</td>\n", $this->ServerPopulation);
} else {
printf("<td>%s</td>\n", $this->ServerStatus);
}
printf("</tr>\n");
$this->ServerName = "";
$this->ServerType = "";
$this->ServerPopulation = "";
$this->ServerStatus = "";
$this->insideitem = false;
}
}
function serverData($parser, $data) {
if ($this->insideitem) {
switch ($this->tag) {
case "POPULATION":
$this->ServerPopulation .= $data;
break;
case "STATUS":
$this->ServerStatus .= $data;
break;
}
}
}
}
$xml_parser = xml_parser_create();
$rss_parser = new RSSParser();
xml_set_object($xml_parser,&$rss_parser);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "serverData");
$fp = fopen("http://www.camelotherald.com/xml/servers.xml","r")
or die("Error reading RSS data.");
while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
fclose($fp);
xml_parser_free($xml_parser);
?>
What could I do so that my data is able to be sorted by either "NAME", "POPULATION", or "TYPE" and then printed directly in function endElement?
I've looked online and in all my book resources and have not found anything that could help me with this without leaning towards MySQL. I know there's gotta be a different way to parse so that items are placed into an array, but I'm unfamiliar with it and unsuccessful in my attempts to do it myself.