TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 101
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 293
  • Total: 293

Why will this code not work in an article?

Started by insanemustang, October 19, 2006, 06:17:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

insanemustang

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>
;

akulion


insanemustang

#2
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

JPDeni

#3
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.

insanemustang

#4
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?"

akulion

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>';

insanemustang

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

akulion

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.

insanemustang

Works as a standalone, but how do I incorporate that into the tp?

JPDeni

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.