Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Moderated Pro PHP
|
Moderated Pro PHP This is a moderated forum for discussing advanced, professional level issues with PHP. Your posts will not appear until a moderator approves them. Posts that are not the right level for this forum will be responded to and you'll be asked to post them in the [url="http://p2p.wrox.com/sql-server-2000-20/9"]Beginning PHP[/url] forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Moderated Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2008, 05:18 PM
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using PHP to create HTML table from external XML

Hi, I posted to the beginner forum, but this may be to advanced for that forum...not sure...can anyone help me? I am having issues outputting my XML document into an HTML table...it works fine, but creates a blank entry for some reason and I cannot seem to get around it. Any help is GREATLY appreciated, the code is below. Thank you!

Below is the PHP code to produce the HTML table from the XML document:


Code:
<?php
function start_tag($parser, $name, $attrs){
    global $table_string;
    $table_string .= "<tr>
        <td width=\"100\" align=left bgcolor=#e7eee8 height=\"120px\" valign=\"middle\">
            <span class=\"listingpadding03\"><img src=\"../images/thumbs/$attrs[title].gif\" width=\"100\" height=\"100\" align=\"middle\" /></span>
        </td>
        <td width=\"90\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[artist]</span>
        </td>
        <td width=\"170\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            $attrs[path]
        </td>
        <td width=\"120px\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[squarefootage]</span>
        </td>
        <td width=\"120px\" align=\"center\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">&nbsp;&nbsp;&nbsp;&nbsp; $attrs[bedsbaths]</span>
        </td>
        <td width=\"90px\" align=\"right\" bgcolor=#e7eee8 height=\"120px\">
            <span class=\"listingpadding03\">$attrs[price] &nbsp;&nbsp;</span>
        </td>
    </tr>
    <tr>
        <td colspan=\"6\" height=\"7\" bgcolor=\"#ffffff\"></td>
    </tr>";
}
function end_tag($parser, $name){}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($parser, "start_tag", "end_tag");
$table_string = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#e7eee8\" width=\"816\" class=\"phptablefont\">
        <tr><td colspan=\"6\" bgcolor=\"#f6f6f6\"><img src=\"../images/list-fo.gif\" alt=\"Buffington Available Homes\" width=\"750\" height=\"22\" /></td></tr><tr><td colspan=\"6\"><img src=\"../images/list-head.gif\" alt=\"Buffington Available Homes\" width=\"816\" height=\"22\" /></td></tr>";
xml_parse($parser, file_get_contents("playlist.xml")) or die("Error parsing XML file");
$table_string .= "</table>";
echo $table_string;
?>

Now below is the raw simple XML file exactly (that the PHP file is reading from - it is named playlist.xml)


Code:
<songs><song title="mckinleya" artist="testing" path="one" squarefootage="two" bedsbaths="three" price="four" /><song title="mckinleya" artist="testing" path="one" squarefootage="two" bedsbaths="three" price="four" /></songs>
Thank you in advance if you can help me!!! -

Ryan
Reply With Quote

C. Ryan McVinney





Similar Threads
Thread Thread Starter Forum Replies Last Post
create XML from database table angshujit ASP.NET 2.0 Basics 0 February 1st, 2007 07:09 AM
transform a xml to a html table robert_trudel_fr XSLT 3 December 3rd, 2006 02:16 PM
XML to HTML Table with Sorting and Distinct VictorMk XSLT 4 April 23rd, 2004 06:29 PM
XML List -> HTML table JPMRaptor XSLT 1 November 14th, 2003 10:19 PM
How to create a string from XML Island in HTML? chandima Javascript How-To 2 October 10th, 2003 02:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.