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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,985
  • Total Topics: 21,321
  • Online today: 677
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 351
  • Total: 351

PHP Article issue

Started by Saiboogu, May 31, 2007, 09:48:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Saiboogu

Can someone help me figure out why the following PHP code works perfectly in a stand-alone document, but produces no results in a PHP article?

if (!$myxml=simplexml_load_file('http://skorcard.net/tootan/kirjutan/top_clans.xml')){
echo 'Error reading the XML file';
}
echo '<table width=\'100%\'>';
foreach ($myxml->entry as $entry) {
if (preg_match('[{PR}]',$entry->name)) {
echo '<tr><td width=\'80%\'>CTF Rank:</td><td>' . $entry->ctfrank . '</td></tr>';
echo '<tr><td>KotH Rank:</td><td>' . $entry->kingrank . '</td></tr>';
echo '<tr><td>Oddball Rank:</td><td>' . $entry->oddballrank . '</td></tr>';
echo '<tr><td>Race Rank:</td><td>' . $entry->racerank . '</td></tr>';
echo '<tr><td>Slayer Rank:</td><td>' . $entry->slayerrank . '</td></tr>';
}
}
echo '</table>';


I developed it in a standalone file - only difference being the HTML surrounding the code --

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<?php

if (!$myxml=simplexml_load_file('http://skorcard.net/tootan/kirjutan/top_clans.xml')){
echo 'Error reading the XML file';
}
echo '<table width=\'100%\'>';
foreach ($myxml->entry as $entry) {
if (preg_match('[{PR}]',$entry->name)) {
echo 
'<tr><td width=\'80%\'>CTF Rank:</td><td>' $entry->ctfrank '</td></tr>';
echo 
'<tr><td>KotH Rank:</td><td>' $entry->kingrank '</td></tr>';
echo 
'<tr><td>Oddball Rank:</td><td>' $entry->oddballrank '</td></tr>';
echo 
'<tr><td>Race Rank:</td><td>' $entry->racerank '</td></tr>';
echo 
'<tr><td>Slayer Rank:</td><td>' $entry->slayerrank '</td></tr>';
}
}
echo '</table>';

?>

</body>
</html>


I create a new PHP article, paste in the code from my first example above, and get a blank article - title, author, view count - just no content.

G6Cad

You cant use that code with in a PHP article.

You have to both remove the php tags <?php ?> ans also you have to echo the html into the php
The mix you have there will not work

Im no coder so i cant make the code work eather, but i do know it cant be mixed like that  :-\

G6Cad

AH!! Sorry, seem to have missread your post, i thought you tried to use the second code in an PHP article

Try this

if (!$myxml=simplexml_load_file('http://skorcard.net/tootan/kirjutan/top_clans.xml'))
{
echo 'Error reading the XML file';
}
echo '<table width=\'100%\'>';
oreach ($myxml->entry as $entry)
{
if (preg_match('[{PR}]',$entry->name))
{
echo '<tr><td width=\'80%\'>CTF Rank:</td><td>' . $entry->ctfrank . '</td></tr>';
echo '<tr><td>KotH Rank:</td><td>' . $entry->kingrank . '</td></tr>';
echo '<tr><td>Oddball Rank:</td><td>' . $entry->oddballrank . '</td></tr>';
echo '<tr><td>Race Rank:</td><td>' . $entry->racerank . '</td></tr>';
echo '<tr><td>Slayer Rank:</td><td>' . $entry->slayerrank . '</td></tr>';
}
echo '</table>';

Saiboogu

Yes - Trying to use the first block of code. Second was just an example of a file that did work, outside of TP.

Tried your code -- after fixing the missing "f" on "foreach" :)

Still no luck, though. :( All you did was remove the indents, right? I already tried removing the biggest ones to keep the code on a single line, hoping that was it -- no luck.

Thanks for the speedy reply though.

G6Cad

Didnt remove them, just separated them to their own lines

G6Cad


Saiboogu

Funny, I was just skimming over that post when I saw new replies over here. Not exact what I'm trying to do, but it still involves reading an XML file -- maybe I can adapt some code, or compare his to mine and find the problem.

One thing I'm thinking of trying (which he did in the tinyRSS example) is remove the bulk of the code to a seperate file and include it. I'll try that when I get home from work, and post my results later.

Thanks for the help, I'll post back after I try a few things.

Saiboogu

Got it. Took a lesson from that other post you referenced and put my code in a seperate file, which I included - works like a charm.

G6Cad


This website is proudly hosted on Crocweb Cloud Website Hosting.