Forums

PHP

This topic is locked

Reordering XML data acending or date

Posted 11 Jun 2004 03:12:05
1
has voted
11 Jun 2004 03:12:05 Anthony Curatola III posted:
I have a question using PHP on how, using a parser script, to display XML data according to date.

My starting code is like this:
//This first looks at the xml data to determine if it is within 60 days (starting from today moving forward).
<?php
$current_date = date("Y m d";
$future_date = date("Y m d",strtotime("+ 60 days");
for( $a=0; $a < $counter_course; ++$a ) {
for( $b=0; $b < $counter_date; ++$b ) {
if($current_date <= $course_data[$a][$b]["short"] AND $future_date >= $course_data[$a][$b]["short"]) {?>

//Build a table that displays course being taught based on xml data that met the requirements above.
<table>
<tr>
<td width="125" align="right" valign="top" bgcolor="#CCCCCC"><b>Description:</b></td>
<td align="left" valign="top"><?php echo $course_data[$a]["description"]; ?></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#CCCCCC"><b>Requirements:</b></td>
<td align="left" valign="top"><?php echo $course_data[$a]["requirements"]; ?></td>
</tr>
</table><br />
<?php
}
}
}?>

XML FILE -- This info is not real but for trial purposes.
<training>
<course>
<date>
<short>2004 07 02</short>
<hour>10</hour>
<minute>00</minute>
<month>7</month>
<day>02</day>
<year>04</year>
</date>
<name>CPA Review Course</name>
<description>This course is designed to give you an overall review of the material for all 4 parts to the CPA exam.</description>
<requirements>Candidate must me actively enrolled to take the CPA exam. Proof of enrollment must be presented prior to payment.</requirements>
<hours>24</hours>
<hoursperclass>8</hoursperclass>
<price>999.95</price>
</course>
</training>

--This does well to list the information -- no question. HOWEVER!!!
My object is to display a month (current to start with) then build the independent tables below it with the courses for that month. My problem is that the xml data is NOT in any order AND i want my php to:
1. identify the month
2. display the month and year [June 2004]
3. create the table below it with the FIRST course being taught (so it should go through the xml file to identify who is first, second and so on)
4. repeat #3 as necessary until no more courses during that month
5. as the date passes by, the course should no longer be displayed for that month [e.g. today=june 15 course 123=june 13&14 will no longer be displayed as no one can register for this course.]
6. REPEAT #1 but increase the month by 1 [July 2004] -- i figure doing this for 3 month span 4 at most.

Can anyone help with how i should do this? I am getting more complicated with this that i think i need to, but i just don't see a more simple approach. I have done searches but unable to find people that have done this already --- but I'm quite sure it has been done before.

Thanks,
Anthony

Reply to this topic