I have tried all manner of small tweaks to this (it is bastardized from stuff I have read on the web). I know there is probably an easy mistake in here, but does anyone see it?
The variables up top are correct.
I know the script is "somewhat" working as it updates the time, but I cannot display/update the data.
$Name="";
$CharID="";
$Title="";
$CR="";
$BR="";
$OP="";
$BH="";
$VSTK="";
$TRTK="";
$TK="";
$KR="";
$KpBH="";
$HBase="";
$PR="";
$Certs="";
$Logged="";
$character=array();
// Define XML parsing functions
function startElement($parser,$Name,$attr){
$GLOBALS['currentElement']=$Name;
}
function endElement($parser,$Name){
$elements=array('Name','CharID','Title','CR','BR','OP','BH','VSTK','TRTK','TK','KR','KpBH','HBase','PR','Certs','Logged','MCount','TotalOutfitKills','TotalOutfitPoints','TotalBaseHacked','AverageCR','AverageBR','AverageOP','AverageBH','AverageTK','AverageKR','AverageKpBH','AveragePR');
if(strcmp($Name,"character")==0){
foreach($elements as $element){
$temp[$element]=$GLOBALS[$element];
}
}
}
function characterData($parser, $data) {
$elements=array('Name','CharID','Title','CR','BR','OP','BH','VSTK','TRTK','TK','KR','KpBH','HBase','PR','Certs','Logged','MCount','TotalOutfitKills','TotalOutfitPoints','TotalBaseHacked','AverageCR','AverageBR','AverageOP','AverageBH','AverageTK','AverageKR','AverageKpBH','AveragePR');
foreach ($elements as $element) {
if ($GLOBALS["currentElement"] == $element) {
$GLOBALS[$element] .= $data;
}
}
}
function parseFile(){
global $xmlSource,$character;
$xml_parser=xml_parser_create();
xml_set_element_handler($xml_parser,"startElement","endElement");
xml_set_character_data_handler($xml_parser,"characterData");
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,false);
$GLOBALS[noxml]=0;
if(!($fp=@fopen($xmlSource,"r"))){
//echo "Cannot locate XML data file: $xmlSource");
$GLOBALS[noxml]=1;
}
while(($data=@fread($fp,4096))){
if(!xml_parse($xml_parser,$data,feof($fp))){
die(sprintf("XML error at line %d column %d ",
xml_get_current_line_number($xml_parser),
xml_get_current_column_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
return $character;
}
// Start the script already!!!
$GLOBALS[xmlSource] = "xml/xml.xml";
$result=parseFile();
// Clear Table
mysql_query("TRUNCATE TABLE stats")
or die( mysql_error() );
// Build table
foreach($result as $arr){
mysql_query("INSERT INTO stats (name, charid, title, cr, br, op, bh, vstk, trtk, tk, kr, kpbh, hbase, pr, certs, logged) VALUES ('$arr[Name]', '$arr[CharID]', '$arr[Title]', '$arr[CR]', '$arr[BR]', '$arr[OP]', '$arr[BH]', '$arr[VSTK]', '$arr[TRTK]', '$arr[TK]', '$arr[KR]', '$arr[KpBH]', '$arr[HBase]', '$arr[PR]', '$arr[Certs]', '$arr[Logged]')")
or die( mysql_error() );
echo "Updated $arr[Name], $arr[CharID]<br />";
}
$curtime=time();
mysql_query("UPDATE ps_outfit_updatetime SET updatetime='$curtime' WHERE timeid='0'")
or die( mysql_error() );