Jump to content

Recommended Posts

Hello all,

 

Im a bit new to php and new to phpfreaks. But thanks in advance for the help!

 

Im parsing an xml feed into a table. The only problem is that one of the fields can not format properly in the table.

 

Here is how the page is working now: http://russiancirclesband.com/tour.php

 

The "With" column is spacing out $OtherArtists out one entry per line, whereas it should have however many $OtherArtists were listed on that line per date.

 

Here is the PHP


<?php

$xml_file = "XML FEED";

$xml_City_key = "*SHOWS*SHOW*CITY";
$xml_VenueName_key = "*SHOWS*SHOW*VENUENAME";
$xml_VenueZip_key = "*SHOWS*SHOW*VENUEZIP";
$xml_VenueAddress_key = "*SHOWS*SHOW*VENUEADDRESS";
$xml_TicketUri_key = "*SHOWS*SHOW*TICKETURI";
$xml_Description_key = "*SHOWS*SHOW*DESCRIPTION";
$xml_VenueUri_key = "*SHOWS*SHOW*VENUEURI";
$xml_Date_key = "*SHOWS*SHOW*DATE";
$xml_TimeSet_key= "*SHOWS*SHOW*TIMESET";
$xml_State_key = "*SHOWS*SHOW*STATE";
$xml_Country_key = "*SHOWS*SHOW*COUNTRY";
$xml_OtherArtists_key = "*SHOWS*SHOW*OTHERARTISTS*NAME";


$Show_array = array();

$counter = 0;
class xml_Show{
    var $City, $VenueName, $VenueZip, $VenueAddress, $TicketUri, $Description, $VenueUri, $Date, $TimeSet, $State, $Country, $OtherArtists ;
}

function startTag($parser, $data){
    global $current_tag;
    $current_tag .= "*$data";
}

function endTag($parser, $data){
    global $current_tag;
    $tag_key = strrpos($current_tag, '*');
    $current_tag = substr($current_tag, 0, $tag_key);
}

function contents($parser, $data){
    global $current_tag, $xml_City_key, $xml_VenueName_key, $xml_VenueZip_key, $xml_VenueAddress_key, $xml_TicketUri_key, $xml_Description_key, $xml_VenueUri_key,  $xml_Date_key,$xml_TimeSet_key, $xml_State_key, $xml_Country_key, $xml_OtherArtists_key, $counter, $Show_array;
    switch($current_tag){
        case $xml_City_key:
            $Show_array[$counter] = new xml_Show();
            $Show_array[$counter]->City = $data;
            break;
	case $xml_VenueName_key:
		$Show_array[$counter]->VenueName = $data;
		break;
	case $xml_VenueZip_key:
		$Show_array[$counter]->VenueZip = $data;
		break;
	case $xml_VenueAddress_key:
		$Show_array[$counter]->VenueAddress = $data;
		break;
	case $xml_TicketUri_key:
		$Show_array[$counter]->TicketUri = $data;
		break;
	case $xml_Description_key:
		$Show_array[$counter]->Description = $data;
		break;
	case $xml_VenueUri_key:
		$Show_array[$counter]->VenueUri = $data;
		break;
        case $xml_Date_key:
            $Show_array[$counter]->Date = $data;
            break;
	case $xml_TimeSet_key:
            $Show_array[$counter]->TimeSet = $data;
            break;
	case $xml_State_key:
            $Show_array[$counter]->State = $data;
		break;
	case $xml_Country_key:
            $Show_array[$counter]->Country = $data;
            break;
	case $xml_OtherArtists_key:
            $Show_array[$counter]->OtherArtists = $data;
            $counter++;
            break;

    }
}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startTag", "endTag");

xml_set_character_data_handler($xml_parser, "contents");


$data = file_get_contents($xml_file);


if(!(xml_parse($xml_parser, $data))){
   die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);


?>

<html>
<head>
<title>Russian Circles - Tour</title>
<style type="text/css">
<!--

#blog {
padding: 15px 15px 15px 60px;
top: 400px;

}
body {
background-image: url(tiledis.gif);
background-repeat: repeat-x;
background-color:#000000;

}

a:link { 
color: #FFFFFF;
text-decoration:underline;
}
a:visited { 
color: #FFFFFF;
text-decoration:underline;
}
.style1 {
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
font-size: 12px;
color: #ffffff;
}

.style2 {
font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
font-size: 12px;
color: #4e4e4e;
}
#whole {
position:absolute;
width:850px;
z-index:1;
top: 0px;
margin-left:auto;
margin-right:auto;
background-color:#ffffff;
}
body,td,th {
color: #FFF;
}

-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></head>
<body>


<br>
<table width="850" align="center" border="1">
<tr>
<td width="100"><div align="center">
<span class="style2">
<u>Date</u>
<br>
</span></div>
</td>
<td width="300"><div align="center">
<span class="style1">  
<u>Location</u>
<br>
</span>
</td></div>
<td width=250"><div align="center">
<span class="style1">
<u>Venue</u>
<br>
</span>
</td>
<td width="350"><div align="center">
<span class="style1">
<u>With</u>
<br></div>
</span>
</td>
<td width="250"><div align="center">
<span class="style1">
<u>Tickets</u>
<br></div>
</span>
</td>
</tr>
<br>



<span class="style1"><div align="center">
  <?php
  
  for($x=0;$x<count($Show_array);$x++){
echo "<tr>";
  	echo "<td>";
    echo "\t" . $Show_array[$x]->Date . "\n";
echo "</td>";

echo "<td>";
if ($Show_array[$x]->Country == "United States") {
     echo "\t" . $Show_array[$x]->City . ","; echo "\t" . $Show_array[$x]->State . " \n";
   
} else {
  echo "\t" . $Show_array[$x]->City . ","; echo "\t" . $Show_array[$x]->Country . " \n";
} 
echo "</td>";

echo "<td>";
echo "\t" . $Show_array[$x]->VenueName . "\n"; 
echo "</td>";

echo "<td>";
echo "\t" . $Show_array[$x]->OtherArtists . "";
echo "</td>";

echo "<td>";
if ($Show_array[$x]->TicketUri == "") {
  echo "<br><br>";
} else {
  echo "<a href='" . $Show_array[$x]->TicketUri . "'>Buy Tickets</a>";
}
echo "</td>";
echo "</tr>";
  }
?>

</table>
</p>
</div>
<br>
<br>
<br>
<table width="665" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="5"><div align="center"><a href="http://russiancirclesband.com"><img src="img/rcgeneva.png" width="300" height="38" border="0" /></a><a href="http://russiancirclesband.com"><img src="img/csoct202009.png" width="300" height="38" border="0" /></a></div></td>
  </tr>
  <tr>
    <td colspan="5"><div align="center"></div></td>
  </tr>
  <tr>
    <td width="133"><div align="center"><a href="http://www.myspace.com/russiancircles" target="_blank"><img src="img/rcspace.png" width="133" height="25" border="0" /></a></div></td>
    <td width="133"><div align="center"><a href="http://russiancircles.hellomerch.com" target="_blank"><img src="img/rcstore.png" width="133" height="25" border="0" /></a></div></td>
    <td width="133"><div align="center"><a href="http://russiancirclesband.blogspot.com/" target="_blank"><img src="img/rcnews.png" width="133" height="25" border="0" /></a></div></td>
    <td width="133"><div align="center"><a href="contact.html" target="_self"><img src="img/rccontacts.png" width="133" height="25" border="0" /></a></div></td>
    <td width="133"><div align="center"><a href="http://www.myspace.com/russiancircles" target="_blank"><img src="img/rctour.png" width="133" height="25" border="0" /></a></div></td>
  </div>
</tr>
</table>
<br>



</body>
</html> 


 

and here is a sample of the xml:

 

<shows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://feeds.artistdata.com/_css/shows.xsd">
	<show>
		<recordKey></recordKey>
		<name><![CDATA[]]></name>
		<city><![CDATA[brooklyn]]></city>
		<venueName><![CDATA[Knitting Factory]]></venueName>
		<venueZip></venueZip>
		<venuePhone>(347)529-6696</venuePhone>

		<venueAddress><![CDATA[361 Metropolitan Ave]]></venueAddress>
		<ticketURI><![CDATA[]]></ticketURI>
		<description><![CDATA[]]></description>
		<ageLimit>All Ages</ageLimit>
		<venueURI><![CDATA[http://ny.knittingfactory.com/index.php]]></venueURI>
		<ticketPrice><![CDATA[ADV $10 DOOR $12]]></ticketPrice>
		<date>2009-12-03</date>
		<timeSet>20:30:00</timeSet>

		<timeDoors></timeDoors>
		<stateAbbreviation>NY</stateAbbreviation>
		<state>New York</state>
		<countryAbbreviation>US</countryAbbreviation>
		<country>United States</country>
		<otherArtists>
			<name><![CDATA[Cast Spells]]></name>

			<uri><![CDATA[http://myspace.com/castspells]]></uri>
		</otherArtists>
		<artistname>Good Old War</artistname>
		<artistKey></artistKey>
	</show>
</shows>

 

So obviously the wall Other Artists are being called is slightly different, but im not exactly sure what is happening. to see what JUST $OtherArtists echo'ing would look like, check out: http://russiancirclesband.com/tour2.php.

 

Not sure what my next move is.

 

Thanks again!

 

 

Link to comment
https://forums.phpfreaks.com/topic/177486-issue-parsing-xml-into-table/
Share on other sites

what version of php are you running?

 

You have a lot of errors you should fix. That's probably why the table isn't formatted the way you want:

 

line 3 - Error: no document type declaration; implying "<!DOCTYPE HTML SYSTEM>"

line 73 column 4 - Error: end tag for "DIV" omitted, but its declaration does not permit this

line 68 column 16 - Info: start tag was here

line 73 column 10 - Error: end tag for element "DIV" which is not open

line 74 column 13 - Error: an attribute specification must start with a name or name token

line 79 column 4 - Error: end tag for "DIV" omitted, but its declaration does not permit this

line 74 column 15 - Info: start tag was here

line 83 column 9 - Error: end tag for "SPAN" omitted, but its declaration does not permit this

line 81 - Info: start tag was here

line 84 column 6 - Error: end tag for element "SPAN" which is not open

line 89 column 9 - Error: end tag for "SPAN" omitted, but its declaration does not permit this

line 87 - Info: start tag was here

line 90 column 6 - Error: end tag for element "SPAN" which is not open

line 93 column 3 - Error: document type does not allow element "BR" here

line 97 column 20 - Error: document type does not allow element "SPAN" here

line 97 column 40 - Error: document type does not allow element "DIV" here; missing one of "APPLET", "OBJECT", "MAP", "IFRAME", "BUTTON" start-tag

line 98 column 5 - Error: document type does not allow element "TR" here

line 101 column 99 - Error: document type does not allow element "TR" here

line 104 column 48 - Error: document type does not allow element "TR" here

line 107 column 93 - Error: document type does not allow element "TR" here

line 110 column 48 - Error: document type does not allow element "TR" here

line 113 column 100 - Error: document type does not allow element "TR" here

line 116 column 48 - Error: document type does not allow element "TR" here

line 119 column 52 - Error: document type does not allow element "TR" here

line 122 column 107 - Error: document type does not allow element "TR" here

line 125 column 48 - Error: document type does not allow element "TR" here

line 128 column 105 - Warning: cannot generate system identifier for general entity "VD"

line 128 column 105 - Error: general entity "VD" not defined and no default entity

line 128 column 107 - Error: reference to entity "VD" for which no system identifier could be generated

line 128 column 104 - Info: entity was defined here

line 128 column 148 - Error: document type does not allow element "TR" here

line 131 column 48 - Error: document type does not allow element "TR" here

line 134 column 95 - Error: document type does not allow element "TR" here

line 137 column 48 - Error: document type does not allow element "TR" here

line 140 column 52 - Error: document type does not allow element "TR" here

line 143 column 48 - Error: document type does not allow element "TR" here

line 146 column 105 - Error: document type does not allow element "TR" here

line 149 column 52 - Error: document type does not allow element "TR" here

line 152 column 48 - Error: document type does not allow element "TR" here

line 155 column 96 - Error: document type does not allow element "TR" here

line 158 column 52 - Error: document type does not allow element "TR" here

line 161 column 48 - Error: document type does not allow element "TR" here

line 164 column 105 - Error: document type does not allow element "TR" here

line 167 column 52 - Error: document type does not allow element "TR" here

line 170 column 49 - Error: document type does not allow element "TR" here

line 173 column 101 - Error: document type does not allow element "TR" here

line 176 column 52 - Error: document type does not allow element "TR" here

line 179 column 99 - Error: document type does not allow element "TR" here

line 182 column 52 - Error: document type does not allow element "TR" here

line 185 column 105 - Error: document type does not allow element "TR" here

line 188 column 52 - Error: document type does not allow element "TR" here

line 191 column 94 - Error: document type does not allow element "TR" here

line 194 column 52 - Error: document type does not allow element "TR" here

line 197 column 50 - Error: document type does not allow element "TR" here

line 200 column 52 - Error: document type does not allow element "TR" here

line 203 column 50 - Error: document type does not allow element "TR" here

line 206 column 52 - Error: document type does not allow element "TR" here

line 209 column 50 - Error: document type does not allow element "TR" here

line 212 column 101 - Error: document type does not allow element "TR" here

line 215 column 50 - Error: document type does not allow element "TR" here

line 218 column 52 - Error: document type does not allow element "TR" here

line 221 column 48 - Error: document type does not allow element "TR" here

line 224 column 52 - Error: document type does not allow element "TR" here

line 227 column 50 - Error: document type does not allow element "TR" here

line 230 column 52 - Error: document type does not allow element "TR" here

line 233 column 50 - Error: document type does not allow element "TR" here

line 236 column 52 - Error: document type does not allow element "TR" here

line 239 column 48 - Error: document type does not allow element "TR" here

line 242 column 52 - Error: document type does not allow element "TR" here

line 245 column 48 - Error: document type does not allow element "TR" here

line 248 column 52 - Error: document type does not allow element "TR" here

line 251 column 48 - Error: document type does not allow element "TR" here

line 254 column 96 - Error: document type does not allow element "TR" here

line 257 column 48 - Error: document type does not allow element "TR" here

line 260 column 52 - Error: document type does not allow element "TR" here

line 263 column 48 - Error: document type does not allow element "TR" here

line 266 column 52 - Error: document type does not allow element "TR" here

line 269 column 48 - Error: document type does not allow element "TR" here

line 272 column 52 - Error: document type does not allow element "TR" here

line 275 column 59 - Error: document type does not allow element "TR" here

line 278 column 52 - Error: document type does not allow element "TR" here

line 281 column 59 - Error: document type does not allow element "TR" here

line 284 column 52 - Error: document type does not allow element "TR" here

line 287 column 59 - Error: document type does not allow element "TR" here

line 290 column 100 - Error: document type does not allow element "TR" here

line 293 column 59 - Error: document type does not allow element "TR" here

line 296 column 52 - Error: document type does not allow element "TR" here

line 299 column 59 - Error: document type does not allow element "TR" here

line 302 column 91 - Error: document type does not allow element "TR" here

line 305 column 59 - Error: document type does not allow element "TR" here

line 308 column 99 - Error: document type does not allow element "TR" here

line 311 column 59 - Error: document type does not allow element "TR" here

line 314 column 97 - Error: document type does not allow element "TR" here

line 317 column 59 - Error: document type does not allow element "TR" here

line 320 column 101 - Error: document type does not allow element "TR" here

line 323 column 59 - Error: document type does not allow element "TR" here

line 326 column 52 - Error: document type does not allow element "TR" here

line 329 column 59 - Error: document type does not allow element "TR" here

line 332 column 91 - Error: document type does not allow element "TR" here

line 335 column 59 - Error: document type does not allow element "TR" here

line 338 column 105 - Error: document type does not allow element "TR" here

line 341 column 59 - Error: document type does not allow element "TR" here

line 344 column 92 - Error: document type does not allow element "TR" here

line 347 column 59 - Error: document type does not allow element "TR" here

line 350 column 104 - Error: document type does not allow element "TR" here

line 354 column 7 - Error: end tag for "DIV" omitted, but its declaration does not permit this

line 97 column 21 - Info: start tag was here

line 354 column 7 - Error: end tag for "SPAN" omitted, but its declaration does not permit this

line 97 - Info: start tag was here

line 355 column 3 - Error: end tag for element "P" which is not open

line 356 column 5 - Error: end tag for element "DIV" which is not open

line 362 column 143 - Error: required attribute "ALT" not specified

line 362 column 255 - Error: required attribute "ALT" not specified

line 368 column 166 - Error: required attribute "ALT" not specified

line 369 column 165 - Error: required attribute "ALT" not specified

line 370 column 167 - Error: required attribute "ALT" not specified

line 371 column 143 - Error: required attribute "ALT" not specified

line 372 column 165 - Error: required attribute "ALT" not specified

line 373 column 7 - Error: end tag for element "DIV" which is not open

 

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.