MadDog 555 Posted November 21, 2007 Share Posted November 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/ Share on other sites More sharing options...
kratsg Posted November 21, 2007 Share Posted November 21, 2007 Check out this documentation: http://us2.php.net/xml Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396103 Share on other sites More sharing options...
prime Posted November 21, 2007 Share Posted November 21, 2007 <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 Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396193 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2007 Share Posted November 21, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396196 Share on other sites More sharing options...
MadDog 555 Posted November 22, 2007 Author Share Posted November 22, 2007 xml will work great but when i use the example prime posted, i get this error: Fatal error: Call to undefined function: simplexml_load_file() in /home/kleinoa/public_html/teams/varsity/roster2.php on line 88 why is this? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396435 Share on other sites More sharing options...
MadDog 555 Posted November 22, 2007 Author Share Posted November 22, 2007 well as i have just learned, simplexml_load_file() requires PHP5 and my server is running PHP 4.47. Is there any other way to do this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396440 Share on other sites More sharing options...
MadDog 555 Posted November 22, 2007 Author Share Posted November 22, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396466 Share on other sites More sharing options...
MadDog 555 Posted November 22, 2007 Author Share Posted November 22, 2007 nevermind, problem solved. i needed a tag to go around everything in my xml. Quote Link to comment https://forums.phpfreaks.com/topic/78272-bring-xml-in-html-using-php/#findComment-396477 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.