Jump to content

Recommended Posts

I am doing a football website and I am making a roster: http://www.kleinoakfootball.com/varsity/roster.php

It is not quite working in firefox safari and opera. I am using php to do multiple includes of huge amounts of data but it is definitely not very efficiant. and very difficult to mannage.

so i thought xml might be able to help.

 

Is it possible to have one xml file, have each article with the stats for each player the xml file. then a php file would somehow print each values in a TD tag and the article in a paragraph tag underneath.

 

an xml entry would look like this:

<player>
<num>65</num>
<name>Tyler Condiff</name>
<pos>OL</pos>
<wt>245</wt>
<ht>5' 10"</ht>
<article>
This is Tyler's sixth year on the gridiron.  He was an integral...
</article>
</player>

 

so the html for every entry would look something like this:

<div>
  <table>
    <td>65</td><td>Tyler Condiff</td><td>OL</td><td>245</td><td>5' 10"</td>
  </table>
  <p>This is Tyler's sixth year on the gridiron.  He was an integral...</p>
</div>

 

then the php would print that code for each player entry

 

Is this at all possible?

 

i know this is possible with flash, but is it with html/php?

Any help would be great!

 

Thanks.

Austin

Link to comment
https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/
Share on other sites

<player>
<num>65</num>
<name>Tyler Condiff</name>
<pos>OL</pos>
<wt>245</wt>
<ht>5' 10"</ht>
<article>
This is Tyler's sixth year on the gridiron.  He was an integral...
</article>
</player>

 

<table>

<?php
  $entries = simplexml_load_file('toollinks.xml');
  foreach ($entries->player as $entry) 
  
  		{
      		        echo "<tr><td>"; 
		echo "$entry->num";
		echo "</td> <td>"; 
		echo "$entry->name";
                        echo "</td> <td>";
                        echo "$entry->pos";
                        echo "</td> <td>";
                        echo "$entry->wt";
                        echo "</td> <td>";
                        echo "$entry->ht";
                        echo "</td> <td>";
                        echo "$entry->article";
		echo "</td></tr>"; 

	}
  ?>
  
</table>

 

This should do what you want

I am using php to do multiple includes of huge amounts of data but it is definitely not very efficiant. and very difficult to mannage.

Based on that, it sounds like you should probably be using a database and then use php to dynamically build the web page, rather than just using php to include pieces of content.

Ok, i followed this tutorial and got it to work, kind of.

http://www.phpfreaks.com/tutorials/44/4.php

 

The problem is, it works fine with one instance of <player> in the xml. but with two or more, i get this error:

Fatal error: Call to undefined function: () in /home/kleinoa/public_html/teams/varsity/roster3.php on line 92

 

This is my PHP:

 

<?php 
function print_error() { 
global $parser; 
die(sprintf("XML Error: %s at line %d", 
xml_error_string($xml_get_error_code($parser)), 
xml_get_current_line_number($parser) 
)); 
}

$parser = xml_parser_create(); 

xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); 

xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); 

$data = implode("",file('roster.xml')); 

for($i=0; $i<count($i_ar['player']); $i++) { 
if($d_ar[$i_ar['player'][$i]]['type']=='open') { 
for($j=$i_ar['player'][$i]; $j<$i_ar['player'][$i+1]; $j++) { 
if($d_ar[$j]['tag'] == 'num') { 
$num = $d_ar[$j]['value']; 
}elseif($d_ar[$j]['tag'] == 'name') { 
$name = $d_ar[$j]['value']; 
}elseif($d_ar[$j]['tag'] == 'pos') { 
$pos = $d_ar[$j]['value'];
}elseif($d_ar[$j]['tag'] == 'gr') { 
$gr = $d_ar[$j]['value'];
}elseif($d_ar[$j]['tag'] == 'wt') { 
$wt = $d_ar[$j]['value'];
}elseif($d_ar[$j]['tag'] == 'ht') { 
$ht = $d_ar[$j]['value'];
}elseif($d_ar[$j]['tag'] == 'article') { 
$article = $d_ar[$j]['value'];
}
} 
echo "<div>";
echo "<span>";
echo "<table>"; 
echo "<tr><td>"; 
echo "$num";
echo "</td> <td>"; 
echo "$name";
echo "</td> <td>";
echo "$pos";
echo "</td> <td>";
echo "$wt";
echo "</td> <td>";
echo "$ht";
echo "</table>";
echo "</span>";
echo "<a><p>";
echo "$article";
echo "</a></p>";  
} 
} 

xml_parser_free($parser); 
?> 

 

Does anyone know whats wrong?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.