XML to PHP stumbling blocks

Hey–So I’m still fairly new at working with PHP, and definitely new at using it to display XML. I’ve got a bit of data I’m trying to sort into tables about upcoming concerts.

I would love to be able to list the concert name as a subheader, and then have 4 columns of that concert’s data below it. Then the next concert subheader, with its data. Ideally, I’d like to order them by date too. The closest I can get is only getting one subheader and ALL the concerts data (and that messy).

Here’s my data. Currently the table is set to have the concert name as the first column. Any advice you can send on would be greatly appreciated!

XML file:

<?xml version=“1.0” encoding=“utf-8”?>

<events>

<concert>
<concertname>St Georges Day Concert</concertname>
<weekday>Wednesday</weekday>
<month>4</month>
<monthdate>22</monthdate>
<year>2009</year>
<when>7.30 p.m.</when>
<venue>St Thomas More RC Church</venue>
<location>Watercall Avenue, Styvechale, Coventry</location>
</concert>

<concert>
<concertname>June Concert</concertname>
<weekday>Saturday</weekday>
<month>6</month>
<monthdate>20</monthdate>
<year>2010</year>
<when>7.30 p.m.</when>
<venue>Polesworth Abbey</venue>
<location>Polesworth, Warwickshire</location>
</concert>

<concert>
<concertname>3rd Concert</concertname>
<weekday>sun</weekday>
<month>2</month>
<monthdate>5</monthdate>
<year>2009</year>
<when>7.30 p.m.</when>
<venue>Ye Olde Church</venue>
<location>urmoms</location>
</concert>

<concert>
<concertname>Heart of England Annual Concert</concertname>
<weekday>sun</weekday>
<month>6</month>
<monthdate>15</monthdate>
<year>2009</year>
<when>7.30 p.m.</when>
<venue>Mark’s house</venue>
<location>Bham</location>
</concert>

</events>

And my php file:

<?php

$xml_file = “concerts.xml”;

$xml_month_key = “EVENTSCONCERTMONTH";
$xml_concertname_key = "EVENTSCONCERT
CONCERTNAME”;
$xml_weekday_key = “EVENTSCONCERTWEEKDAY";
$xml_monthdate_key = "EVENTSCONCERT
MONTHDATE”;
$xml_year_key = “EVENTSCONCERTYEAR";
$xml_when_key = "EVENTSCONCERT
WHEN”;
$xml_venue_key = “EVENTSCONCERTVENUE";
$xml_location_key = "EVENTSCONCERT
LOCATION”;

$story_array = array();

$counter = 0;
class xml_story{
var $month, $concertname, $weekday, $monthdate, $year, $when, $venue, $location;
}

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_month_key, $xml_concertname_key, $xml_weekday_key, $xml_monthdate_key, $xml_year_key, $xml_when_key, $xml_venue_key, $xml_location_key, $counter, $story_array;
switch($current_tag){
case $xml_concertname_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->concertname = $data;
break;
case $xml_month_key:
$story_array[$counter]->month = $data;
break;
case $xml_weekday_key:
$story_array[$counter]->weekday = $data;
break;
case $xml_monthdate_key:
$story_array[$counter]->monthdate = $data;
break;
case $xml_year_key:
$story_array[$counter]->year = $data;
break;
case $xml_when_key:
$story_array[$counter]->when = $data;
break;
case $xml_venue_key:
$story_array[$counter]->venue = $data;
break;
case $xml_location_key:
$story_array[$counter]->location = $data;
$counter++;
break;
}
}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, “startTag”, “endTag”);

xml_set_character_data_handler($xml_parser, “contents”);

$fp = fopen($xml_file, “r”) or die(“Could not open file”);

$data = fread($fp, filesize($xml_file)) or die(“Could not read file”);

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

xml_parser_free($xml_parser);

fclose($fp);

?>

<html>
<head>
<title>The Concert Orchestra</title>
<link href=“lookandfeel/main.css” type=“text/css” rel=“stylesheet” />
</head>

<body bgcolor="#330100" leftmargin=“0” topmargin=“0” marginwidth=“0” marginheight=“0”>
<table width=“800” border=“0” cellspacing=“0” cellpadding=“0” class=“tabletext”>
<tr>
<td colspan=“5”>
<b>2009</b></td>
</tr>
<tr>
<td>

&lt;?php

for($x=0;$x<count($story_array);$x++){
echo $story_array[$x]->concertname . “</br>”;}
?></td>

&lt;td&gt;

<?php
for($x=0;$x<count($story_array);$x++){

if ($story_array[$x]-&gt;month == 1) {
    echo "January" ;
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 2) {
    echo "February" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 3) {
    echo "March" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 4) {
    echo "April" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 5) {
    echo "May" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 6) {
    echo "June" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 7) {
    echo "July" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 8) {
    echo "August" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 9) {
    echo "September" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 10) {
    echo "October" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 11) {
    echo "November" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} elseif ($story_array[$x]-&gt;month == 12) {
    echo "December" ;    
    echo "&nbsp;" . $story_array[$x]-&gt;monthdate . "&lt;/br&gt;";
} else {
    echo "TBA";
}

}

?>
</td>
<td><?php
for($x=0;$x<count($story_array);$x++){
echo $story_array[$x]->when . “</br>”;}
?>
<td>

&lt;?php

for($x=0;$x<count($story_array);$x++){
echo $story_array[$x]->venue . “</br>”;}
?></td>
</td>
<td><?php
for($x=0;$x<count($story_array);$x++){
echo $story_array[$x]->location . “</br>”;
}
?></td>
</tr>

</table>

</body>
</html>