TinyPortal

Development => Block Codes => Topic started by: insanemustang on October 19, 2006, 06:17:05 AM

Title: Why will this code not work in an article?
Post by: insanemustang on October 19, 2006, 06:17:05 AM
Just wondering if anyone could tell me why this code on this article page
http://www.loh-clan.net/index.php?cat=170

Will not display correctly?

Quote<table width="600" border="0" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top" background="images/metal.jpg" class="newshead"><img src="images/spacer.gif" width="20"

height="1">LOH BF2 Stats</td>
    </tr>
   <tr><td class="text1" align="center">XML Feed courtesy of <a href="http://www.bf2tracker.com"

target="_blank">BF2Tracker.com</a></td>
   </tr>
   <tr><td>&nbsp;</td>
   </tr>
    <tr>
      <td>
<?php
$clanid="9324";


function startTag($parser, $name, $attrs) {
global $stack;

$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}

function cdata($parser, $cdata) {
global $stack,$i;

if(trim($cdata)) {

$stack[count($stack)-1]['cdata']=$cdata;
}

}

function endTag($parser, $name) {
global $stack;

$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

$xmllink="http://bf2tracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!$data) die ("<table width=400><tr><td colspan=\"3\" align=center><font face=arial size=\"1\">Battling

Highlanders</td></tr><tr><td>&nbsp;</td></tr><tr><td><center><font face=arial size=\"2\">BF2Tracker.com XML feed is

currently <font color=red>OFFLINE</font></font></center></td></tr></table>");

xml_parser_free($xml_parser);


// Get Data

// Get Player Data
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
for($x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
$valname=$stack[0][children][2][children][$i][children][$x][name];
$value=$stack[0][children][2][children][$i][children][$x][cdata];
if($valname=="PLAYERID") $pid=$value;
$playerstats[$pid][$valname]=$value;
}
}

// Get Clan Profile Data
for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
$valname=$stack[0][children][0][children][$i][name];
$claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

// Get Clan Stats Data
for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
$valname=$stack[0][children][1][children][$i][name];
$clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}


// Now we have 3 arrays with all stats and infos
// print_r($playerstats);
// print_r($claninfo);
// print_r($clanstats);

// Display Player Stats
echo "<table width=\"600\"><tr><td bgcolor=#ADD8E6 align=center width=\"40\"><font face=verdana

size=1>Rank</td><td width=\"60\" bgcolor=#ADD8E6 align=center><font face=verdana size=1>Status</td><td

width=\"60\">Player</td><td width=\"20\"></td><td width=\"20\"></td><td width=\"50\">GS</td><td

width=\"50\">Kills</td><td width=\"50\">Deaths</td><td colspan=\"2\" width=\"130\">Progress</td></tr>";

foreach($playerstats as $key => $value) {

$playername=$playerstats[$key][PLAYERNAME];
$playerurl=$playerstats[$key][PLAYERSTATSURL];
$playerCO=$playerstats[$key][PLAYERCOUNTRY];
$playerglobal=$playerstats[$key][PLAYERGLOBALSCORE];
$playerkills=$playerstats[$key][PLAYERKILLS];
$playerdeaths=$playerstats[$key][PLAYERDEATHS];

//Private                  0
//Private First Class         150
//Lance Corporal            500
//Corporal                  800
//Sergeant                  2500
//Staff Sergeant            5000
//Gunnery Sergeant            8000
//Master Sergeant            20000
//First Sergeant            20000
//Master Gunnery Sergeant      50000
//Sergeant Major            50000
//Sergeant Major of the Corps   50000
//2nd Lieutnant               60000
//1st Lieutnant               75000
//Captain                  90000
//Major                     115000
//Lieutnant Colonel            125000
//Colonel                  150000
//Brigadier General            180000
//Major General               180000
//Lieutnant General            200000
//General                  200000

if($playerstats[$key][PLAYERRANK]!="") $playerrank=$playerstats[$key][PLAYERRANK];
else $playerrank=0;

if($playerstats[$key][PLAYERRANK]==1) {$stripe="PFC"; $target=350; $adjust=150;

}elseif($playerstats[$key][PLAYERRANK]==2) {$stripe="L/Cpl"; $target=300; $adjust=500;

}elseif($playerstats[$key][PLAYERRANK]==3) {$stripe="Cpl"; $target=1700; $adjust=800;

}elseif($playerstats[$key][PLAYERRANK]==4) {$stripe="Sgt"; $target=2500; $adjust=2500;

}elseif($playerstats[$key][PLAYERRANK]==5) {$stripe="Staff&nbsp;Sgt"; $target=3000; $adjust=5000;

}elseif($playerstats[$key][PLAYERRANK]==6) {$stripe="Gunnery&nbsp;Sgt"; $target=12000; $adjust=8000;

}elseif($playerstats[$key][PLAYERRANK]==7) {$stripe="Master&nbsp;Sgt"; $target=30000; $adjust=20000;

}elseif($playerstats[$key][PLAYERRANK]==8) {$stripe="1st&nbsp;Sgt"; $target=30000; $adjust=20000;

}elseif($playerstats[$key][PLAYERRANK]==9) {$stripe="Master&nbsp;Gunnery&nbsp;Sgt"; $target=10000; $adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==10) {$stripe="Sgt&nbsp;Major"; $target=10000; $adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==11) {$stripe="Sgt&nbsp;Major&nbsp;of&nbsp;the&nbsp;Corps"; $target=10000;

$adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==12) {$stripe="2nd&nbsp;Lieutnant"; $target=15000; $adjust=60000;

}elseif($playerstats[$key][PLAYERRANK]==13) {$stripe="1st&nbsp;Lieutnant"; $target=15000; $adjust=75000;

}elseif($playerstats[$key][PLAYERRANK]==14) {$stripe="Captain"; $target=25000; $adjust=90000;

}elseif($playerstats[$key][PLAYERRANK]==15) {$stripe="Major"; $target=10000; $adjust=115000;

}elseif($playerstats[$key][PLAYERRANK]==16) {$stripe="Lieutnant&nbsp;Colonel"; $target=25000; $adjust=125000;

}elseif($playerstats[$key][PLAYERRANK]==17) {$stripe="Colonel"; $target=30000; $adjust=150000;

}elseif($playerstats[$key][PLAYERRANK]==18) {$stripe="Brigadier&nbsp;General"; $target=20000; $adjust=180000;

}elseif($playerstats[$key][PLAYERRANK]==19) {$stripe="Major&nbsp;General"; $target=20000; $adjust=180000;

}elseif($playerstats[$key][PLAYERRANK]==20) {$stripe="Lieutnant&nbsp;General"; $target=300000; $adjust=200000;

}elseif($playerstats[$key][PLAYERRANK]==21) {$stripe="General"; $target=300000; $adjust=200000;

}else {$stripe="Private"; $target=150; $adjust=0;}

if($target<>0) $progress=round(($playerglobal-$adjust)/$target*100,0);
else $progress="n/a";

if($target<>0) $needed=(($target+$adjust)-$playerglobal);
else $needed="n/a";

if($needed<100) $alert="red";
else $alert="white";

if($playerstats[$key][PLAYERCOUNTRY]!="-") $playerCO=$playerstats[$key][PLAYERCOUNTRY];
else $playerCO="unknown";

if($playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
else $statuspic="poffline.gif";

echo "<tr><td align=\"center\"><img valign=center border=\"0\" src=\"./images/ranksmall_$playerrank.gif\"

width=\"16\" height=\"16\" alt=$stripe title=$stripe></td><td><img valign=center border=\"0\"

src=\"./images/$statuspic\" width=\"42\" height=\"16\" align=center></td><td><font

size=\"2\">$playername</font></td><td><a target=\"_blank\" href=\"$playerurl\"><img valign=baseline border=\"0\"

src=\"./images/crosshairs.jpg\" width=\"16\" height=\"16\" alt=\"View $playername's stats\" title=\"View

$playername's stats\"></a></td><td><img border=\"0\" src=\"./images/$playerCO.gif\" width=\"16\"

height=\"12\"></td><td><font size=\"2\">$playerglobal</font></td><td><font

size=\"2\">$playerkills</font></td><td><font size=\"2\">$playerdeaths</font></td><td align=center><font

size=\"2\">$progress %</font></td><td><table bgcolor=#122537 border=1 bordercolor=#5C88B5 width=100 cellpadding=0

cellspacing=0><tr><td><img border=0 src=\"./images/userrating_yellow.gif\" width=$progress%

height=6></td></tr></table></td><td align=\"center\"><font color=\"$alert\" size=\"2\">$needed</font></td></tr>";
}
echo "</table>
";

// Display Clan Info

foreach($claninfo as $key => $value) {
echo "<font size=\"2\">$key: $value</font>
\n";
}


// Display Clan Stats
foreach($clanstats as $key => $value) {
echo "<font size=\"2\">$key: $value</font>
\n";
}
?>
</table>
</td></tr>
<tr><td>&nbsp;</td></tr></table>
;
Title: Re: Why will this code not work in an article?
Post by: akulion on October 19, 2006, 06:37:31 AM
u will have to use a php Article
Title: Re: Why will this code not work in an article?
Post by: insanemustang on October 19, 2006, 06:47:05 AM
I tried that too

I made it into a php article, now im getting an error on the load page?

http://www.loh-clan.net/index.php?cat=170
Title: Re: Why will this code not work in an article?
Post by: JPDeni on October 19, 2006, 06:50:29 AM
As aku said, you have to use a php article. All of your html at the beginning must go in echo statements and you have to get rid of the <?php and ?> tags.

If you put it in a php article and do the necessary edits and you still have problems, come back and tell us exactly what the problem is and we'll see if we can figure it out.

Edited to add:
Your error is due to the html that's outside of an echo statement.
Title: Re: Why will this code not work in an article?
Post by: insanemustang on October 19, 2006, 07:05:19 AM
I'm not sure exactly where, or what to add where?  I appreciate you guys help for real, but can you be just a little more specific?  I see echo's in places already, and some of the html is not in echo's...some towards the bottom...what do I put in echo's and what don't I?

And what exactly does adding an echo look like?  echo "html?"
Title: Re: Why will this code not work in an article?
Post by: akulion on October 19, 2006, 07:14:48 AM
try this code in a php article


echo'<table width="600" border="0" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top" background="images/metal.jpg" class="newshead"><img src="images/spacer.gif" width="20"

height="1">LOH BF2 Stats</td>
    </tr>
   <tr><td class="text1" align="center">XML Feed courtesy of BF2Tracker.com</td>
   </tr>
   <tr><td>&nbsp;</td>
   </tr>
    <tr>
      <td>';

$clanid="9324";


function startTag($parser, $name, $attrs) {
global $stack;

$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}

function cdata($parser, $cdata) {
global $stack,$i;

if(trim($cdata)) {

$stack[count($stack)-1]['cdata']=$cdata;
}

}

function endTag($parser, $name) {
global $stack;

$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

$xmllink="http://bf2tracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!$data) die ("<table width=400><tr><td colspan=\"3\" align=center><font face=arial size=\"1\">Battling

Highlanders</td></tr><tr><td>&nbsp;</td></tr><tr><td><center><font face=arial size=\"2\">BF2Tracker.com XML feed is

currently <font color=red>OFFLINE</font></font></center></td></tr></table>");

xml_parser_free($xml_parser);


// Get Data

// Get Player Data
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
for($x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
$valname=$stack[0][children][2][children][$i][children][$x][name];
$value=$stack[0][children][2][children][$i][children][$x][cdata];
if($valname=="PLAYERID") $pid=$value;
$playerstats[$pid][$valname]=$value;
}
}

// Get Clan Profile Data
for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
$valname=$stack[0][children][0][children][$i][name];
$claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

// Get Clan Stats Data
for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
$valname=$stack[0][children][1][children][$i][name];
$clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}


// Now we have 3 arrays with all stats and infos
// print_r($playerstats);
// print_r($claninfo);
// print_r($clanstats);

// Display Player Stats
echo "<table width=\"600\"><tr><td bgcolor=#ADD8E6 align=center width=\"40\"><font face=verdana

size=1>Rank</td><td width=\"60\" bgcolor=#ADD8E6 align=center><font face=verdana size=1>Status</td><td

width=\"60\">Player</td><td width=\"20\"></td><td width=\"20\"></td><td width=\"50\">GS</td><td

width=\"50\">Kills</td><td width=\"50\">Deaths</td><td colspan=\"2\" width=\"130\">Progress</td></tr>";

foreach($playerstats as $key => $value) {

$playername=$playerstats[$key][PLAYERNAME];
$playerurl=$playerstats[$key][PLAYERSTATSURL];
$playerCO=$playerstats[$key][PLAYERCOUNTRY];
$playerglobal=$playerstats[$key][PLAYERGLOBALSCORE];
$playerkills=$playerstats[$key][PLAYERKILLS];
$playerdeaths=$playerstats[$key][PLAYERDEATHS];

//Private                  0
//Private First Class         150
//Lance Corporal            500
//Corporal                  800
//Sergeant                  2500
//Staff Sergeant            5000
//Gunnery Sergeant            8000
//Master Sergeant            20000
//First Sergeant            20000
//Master Gunnery Sergeant      50000
//Sergeant Major            50000
//Sergeant Major of the Corps   50000
//2nd Lieutnant               60000
//1st Lieutnant               75000
//Captain                  90000
//Major                     115000
//Lieutnant Colonel            125000
//Colonel                  150000
//Brigadier General            180000
//Major General               180000
//Lieutnant General            200000
//General                  200000

if($playerstats[$key][PLAYERRANK]!="") $playerrank=$playerstats[$key][PLAYERRANK];
else $playerrank=0;

if($playerstats[$key][PLAYERRANK]==1) {$stripe="PFC"; $target=350; $adjust=150;

}elseif($playerstats[$key][PLAYERRANK]==2) {$stripe="L/Cpl"; $target=300; $adjust=500;

}elseif($playerstats[$key][PLAYERRANK]==3) {$stripe="Cpl"; $target=1700; $adjust=800;

}elseif($playerstats[$key][PLAYERRANK]==4) {$stripe="Sgt"; $target=2500; $adjust=2500;

}elseif($playerstats[$key][PLAYERRANK]==5) {$stripe="Staff&nbsp;Sgt"; $target=3000; $adjust=5000;

}elseif($playerstats[$key][PLAYERRANK]==6) {$stripe="Gunnery&nbsp;Sgt"; $target=12000; $adjust=8000;

}elseif($playerstats[$key][PLAYERRANK]==7) {$stripe="Master&nbsp;Sgt"; $target=30000; $adjust=20000;

}elseif($playerstats[$key][PLAYERRANK]==8) {$stripe="1st&nbsp;Sgt"; $target=30000; $adjust=20000;

}elseif($playerstats[$key][PLAYERRANK]==9) {$stripe="Master&nbsp;Gunnery&nbsp;Sgt"; $target=10000; $adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==10) {$stripe="Sgt&nbsp;Major"; $target=10000; $adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==11) {$stripe="Sgt&nbsp;Major&nbsp;of&nbsp;the&nbsp;Corps"; $target=10000;

$adjust=50000;

}elseif($playerstats[$key][PLAYERRANK]==12) {$stripe="2nd&nbsp;Lieutnant"; $target=15000; $adjust=60000;

}elseif($playerstats[$key][PLAYERRANK]==13) {$stripe="1st&nbsp;Lieutnant"; $target=15000; $adjust=75000;

}elseif($playerstats[$key][PLAYERRANK]==14) {$stripe="Captain"; $target=25000; $adjust=90000;

}elseif($playerstats[$key][PLAYERRANK]==15) {$stripe="Major"; $target=10000; $adjust=115000;

}elseif($playerstats[$key][PLAYERRANK]==16) {$stripe="Lieutnant&nbsp;Colonel"; $target=25000; $adjust=125000;

}elseif($playerstats[$key][PLAYERRANK]==17) {$stripe="Colonel"; $target=30000; $adjust=150000;

}elseif($playerstats[$key][PLAYERRANK]==18) {$stripe="Brigadier&nbsp;General"; $target=20000; $adjust=180000;

}elseif($playerstats[$key][PLAYERRANK]==19) {$stripe="Major&nbsp;General"; $target=20000; $adjust=180000;

}elseif($playerstats[$key][PLAYERRANK]==20) {$stripe="Lieutnant&nbsp;General"; $target=300000; $adjust=200000;

}elseif($playerstats[$key][PLAYERRANK]==21) {$stripe="General"; $target=300000; $adjust=200000;

}else {$stripe="Private"; $target=150; $adjust=0;}

if($target<>0) $progress=round(($playerglobal-$adjust)/$target*100,0);
else $progress="n/a";

if($target<>0) $needed=(($target+$adjust)-$playerglobal);
else $needed="n/a";

if($needed<100) $alert="red";
else $alert="white";

if($playerstats[$key][PLAYERCOUNTRY]!="-") $playerCO=$playerstats[$key][PLAYERCOUNTRY];
else $playerCO="unknown";

if($playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
else $statuspic="poffline.gif";

echo "<tr><td align=\"center\"><img valign=center border=\"0\" src=\"./images/ranksmall_$playerrank.gif\"

width=\"16\" height=\"16\" alt=$stripe title=$stripe></td><td><img valign=center border=\"0\"

src=\"./images/$statuspic\" width=\"42\" height=\"16\" align=center></td><td><font

size=\"2\">$playername</font></td><td><a target=\"_blank\" href=\"$playerurl\"><img valign=baseline border=\"0\"

src=\"./images/crosshairs.jpg\" width=\"16\" height=\"16\" alt=\"View $playername's stats\" title=\"View

$playername's stats\">[/url]</td><td><img border=\"0\" src=\"./images/$playerCO.gif\" width=\"16\"

height=\"12\"></td><td><font size=\"2\">$playerglobal</font></td><td><font

size=\"2\">$playerkills</font></td><td><font size=\"2\">$playerdeaths</font></td><td align=center><font

size=\"2\">$progress %</font></td><td><table bgcolor=#122537 border=1 bordercolor=#5C88B5 width=100 cellpadding=0

cellspacing=0><tr><td><img border=0 src=\"./images/userrating_yellow.gif\" width=$progress%

height=6></td></tr></table></td><td align=\"center\"><font color=\"$alert\" size=\"2\">$needed</font></td></tr>";
}
echo "</table>
";

// Display Clan Info

foreach($claninfo as $key => $value) {
echo "<font size=\"2\">$key: $value</font>
\n";
}


// Display Clan Stats
foreach($clanstats as $key => $value) {
echo "<font size=\"2\">$key: $value</font>
\n";
}
echo'
</table>
</td></tr>
<tr><td>&nbsp;</td></tr></table>';
Title: Re: Why will this code not work in an article?
Post by: insanemustang on October 19, 2006, 07:28:49 AM
Hey, that kind of worked...but it didn't pull in any of the stats...thank you for trying to help me

http://www.loh-clan.net/index.php?cat=170
Title: Re: Why will this code not work in an article?
Post by: akulion on October 19, 2006, 07:46:52 AM
well why u PHP code wont function - i have no clue, since it could be something wrong with the programming itself for all I know

but u could try a few things...

Try putting the code in a .php file and uploading to the server and see if it works as a stand alone or not.
Title: Re: Why will this code not work in an article?
Post by: insanemustang on October 19, 2006, 03:31:52 PM
Works as a standalone, but how do I incorporate that into the tp?
Title: Re: Why will this code not work in an article?
Post by: JPDeni on October 19, 2006, 03:57:20 PM
You might take a look at your error log and see what's there. If you've got a whole lot of stuff (pages and pages), clear out the whole thing, then go to the page with your code and then go directly to the error log again. You'll have a better chance of just getting errors from that one script.
Title: Re: Why will this code not work in an article?
Post by: akulion on October 19, 2006, 04:03:04 PM
Quote from: insanemustang on October 19, 2006, 03:31:52 PM
Works as a standalone, but how do I incorporate that into the tp?

i have seen this problem before - but no solution was found for it
dont know what could be causing it
Title: Re: Why will this code not work in an article?
Post by: IchBin on October 19, 2006, 04:34:55 PM
Try including the script in a PHP article/block.

include('path/to/your/file.html');
Title: Re: Why will this code not work in an article?
Post by: jacortina on October 19, 2006, 05:08:00 PM
Just add "global $stack;" to the top of the block.

I think this is a quirk of separately eval'd code; it's like it's treated as if it's a discrete function. So, to share the data in $stack, you have to $global it.
Title: Re: Why will this code not work in an article?
Post by: insanemustang on October 20, 2006, 05:48:12 AM
You guys are good, got it working perfectly.

You can see a block "BF2 Player Stats" on the right side (http://www.loh-clan.net) and then a link below it to go into the article format.

Thanks for everything
Title: Re: Why will this code not work in an article?
Post by: D@ve on November 22, 2006, 08:47:30 PM
i too am trying to use this feed from bf2 tracker for my clans website, and what to add it in our new tp site that is in the works. but i am a noob when it comes to all this php and any help would be greatly appreciated. the code iam using worked great as long as your php isnt displaying errors, but since we moved our site to a new host and the php is set to display errors. the page is filled with lots of errors and just cant be used until its fixed. so i was hoping that someone could help me figure out the errors in this code so i may use it for the new tp site. here is the code i currenty use for the page its on <html>
<head>
<title>Specialist Clan BF2 Stats</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#000000" background="images/grid.jpg" text="#FFFFFF" link="#00CC00" vlink="#009900" alink="#009900">
<div align="center">
<?php
$clanid
="4534";

function
startTag($parser, $name, $attrs) {
global
$stack;

$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}

function
cdata($parser, $cdata) {
global
$stack;

$stack[count($stack)-1]['cdata'] .= $cdata;  
}

function
endTag($parser, $name) {
global
$stack;

$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

$xmllink="http://bf2tracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!
$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));

xml_parser_free($xml_parser);


// Get Data

// Get Clan Profile Data
for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
 
$valname=$stack[0][children][0][children][$i][name];
 
$claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

// Get Clan Stats Data
for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
 
$valname=$stack[0][children][1][children][$i][name];
 
$clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}

// Get Player Data
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
 for(
$x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
 
$valname=$stack[0][children][2][children][$i][children][$x][name];
 
$value=$stack[0][children][2][children][$i][children][$x][cdata];
  if(
$valname=="PLAYERID") $pid=$value;
 
$playerstats[$pid][$valname]=$value;
 }
}

// Now we have 3 arrays with all stats and infos
// print_r($claninfo);
// print_r($clanstats);
// print_r($playerstats);

// Display Clan Info
echo "<b>Clan Info:</b><br>\n";

foreach(
$claninfo as $key => $value) {
echo
"$key: $value<br>\n";
}


// Display Clan Stats
echo "<br><br><b>Clan Info:</b><br>\n";

foreach(
$clanstats as $key => $value) {
echo
"$key: $value<br>\n";
}

// Display Player Stats
echo "<br><br><b>Player Stats:</b><br>\n";

foreach(
$playerstats as $key => $value) {
$playername=$playerstats[$key][PLAYERNAME];
$playerurl=$playerstats[$key][PLAYERSTATSURL];

if(
$playerstats[$key][PLAYERRANK]!="") $playerrank=$playerstats[$key][PLAYERRANK];
else
$playerrank=0;

if(
$playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
else
$statuspic="poffline.gif";

echo
"<img border=\"0\" src=\"./images/ranksmall_$playerrank.gif\" width=\"16\" height=\"16\"> <img border=\"0\" src=\"./images/$statuspic\" width=\"42\" height=\"16\"> <a target=\"_blank\" href=\"$playerurl\"><font size=\"2\" color=\"#FFFFFF\">$playername</font></a><br>";
}
?>
<font face="Arial, Helvetica, sans-serif"></font></div>
</body>
</html>

and you can see the errors here http://www.spcclan.com/spc/bf2_clan.php (http://www.spcclan.com/spc/bf2_clan.php)
Title: Re: Why will this code not work in an article?
Post by: IchBin on November 23, 2006, 07:45:10 AM
Its because of the <?php and ?> tags. If you can get rid of those and turn the whole code into echo'd HTML, it should work I think.

For example...
Instead of:
?>
<font face="Arial, Helvetica, sans-serif"></font></div>
</body>
</html>


Do this:
echo '
<font face="Arial, Helvetica, sans-serif"></font></div>
</body>
</html>';
Title: Re: Why will this code not work in an article?
Post by: D@ve on November 25, 2006, 06:03:32 AM
thanks ichbin, not really the help i was looking for. i figured out how to add as a php article just this code has too many errors and was wondering if anyone might know what is wrong with it. i dont much about any of this I just try try try. but to me seems like its trying to pull to deep from the xml file and their is nothing to pull from? short iam not sure haha
Title: Re: Why will this code not work in an article?
Post by: IchBin on November 25, 2006, 07:42:51 AM
If you want help, it might benefit you to post the errors you get instead of making anyone who wants to help take the time to replicate everything your doing.
Title: Re: Why will this code not work in an article?
Post by: JPDeni on November 25, 2006, 01:32:12 PM
This works without syntax errors:


$clanid="4534";

function startTag($parser, $name, $attrs) {
global $stack;

$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($stack,$tag);
}

function cdata($parser, $cdata) {
global $stack;

$stack[count($stack)-1]['cdata'] .= $cdata;   
}

function endTag($parser, $name) {
global $stack;

$stack[count($stack)-2]['children'][] = $stack[count($stack)-1];
array_pop($stack);
}


// Parse XML

$stack = array();
$claninfo = array();
$clanstats = array();
$playerstats = array();

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "cdata");

$xmllink="http://bf2tracker.com/livefeed/xml_clanprofile.php?clanid=$clanid";
$data = xml_parse($xml_parser,file_get_contents($xmllink));
if(!$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));

xml_parser_free($xml_parser);


// Get Data

// Get Clan Profile Data
for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) {
  $valname=$stack[0][children][0][children][$i][name];
  $claninfo[$valname]=$stack[0][children][0][children][$i][cdata];
}

// Get Clan Stats Data
for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) {
  $valname=$stack[0][children][1][children][$i][name];
  $clanstats[$valname]=$stack[0][children][1][children][$i][cdata];
}

// Get Player Data
for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) {
  for($x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) {
   $valname=$stack[0][children][2][children][$i][children][$x][name];
   $value=$stack[0][children][2][children][$i][children][$x][cdata];
   if($valname=="PLAYERID") $pid=$value;
   $playerstats[$pid][$valname]=$value;
  }
}

// Now we have 3 arrays with all stats and infos
// print_r($claninfo);
// print_r($clanstats);
// print_r($playerstats);

// Display Clan Info
echo "<b>Clan Info:</b><br>\n";

foreach($claninfo as $key => $value) {
echo "$key: $value<br>\n";
}


// Display Clan Stats
echo "<br><br><b>Clan Info:</b><br>\n";

foreach($clanstats as $key => $value) {
echo "$key: $value<br>\n";
}

// Display Player Stats
echo "<br><br><b>Player Stats:</b><br>\n";

foreach($playerstats as $key => $value) {
$playername=$playerstats[$key][PLAYERNAME];
$playerurl=$playerstats[$key][PLAYERSTATSURL];

if($playerstats[$key][PLAYERRANK]!="") $playerrank=$playerstats[$key][PLAYERRANK];
else $playerrank=0;

if($playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif";
else $statuspic="poffline.gif";

echo '<img border="0" src="./images/ranksmall_' . $playerrank . '.gif" width="16" height="16"> <img border="0" src="./images/' . $statuspic . '" width="42" height="16"> <a target="_blank" href="' . $playerurl . '"><font size="2" color="#FFFFFF">' . $playername . '</font></a><br>';
}


You don't need all of the opening and closing html stuff. That's taken care of through TP. You can't have the <?php and ?> tags because the whole thing goes through an "eval" function. And, I think because of the "eval" thing all of the escaped quotes will cause you problems. Notice the difference between the last real line of the code I posted and the similar line in the one you posted.

I can't guarantee that the actual programming will work, :) but you won't get any syntax errors.
Title: Re: Why will this code not work in an article?
Post by: D@ve on November 25, 2006, 07:12:42 PM
Guys thanks for the help so far but i will drop this cause its not tp related and i understand this support is for tp in general and dont want to burn any bridges. just thought their might be a mind out their that new what was wrong with this standalone php page first before i added to the tp site "you guys already provided enough help for adding it". i didnt think i had any problems with it tell we moved our site to a host that will not turn off displaying php errors. which is a good thing really i guess, caught this. the creator of this page told me to just turn off the displaying of errors and move on. no other solution. i just need to learn more about php cause errors is something i dont want, displayed or not. they just lead to problems down the line.

IchBin sorry i didnt post or provide a pic with errors thought my link i added to the actual page would visually show the errors much better and in real time. http://www.spcclan.com/spc/bf2_clan.php (http://www.spcclan.com/spc/bf2_clan.php)