How to get PHP to Order by Day of Month when processing an XML file Options

P

Phill.Booth

Hello I need to get PHP to order the output of the XML file to be
ACENDING to the numerical value of the XML <start_day></start_day>
tags

PHP Script...
<?php
function makexmltree($getmonth) {


$doc = new DOMDocument();
$doc->load( 'newxml.xml' );
//gets info from xml


$icount == 1;
echo "<br><table width='100%' border='0' cellpadding='5'
cellspacing='0' class='table_searchresult2'>";


$books = $doc->getElementsByTagName( "event" );
foreach( $books as $book )
{


$product_nos = $book->getElementsByTagName( "product_no" );
$product_no = $product_nos->item(0)->nodeValue;


$product_codes = $book-

getElementsByTagName( "product_code" );


$product_code = $product_codes->item(0)->nodeValue;

$product_names = $book-

getElementsByTagName( "product_name" );


$product_name = $product_names->item(0)->nodeValue;

$event_venues = $book-

getElementsByTagName( "event_venue" );


$event_venue = $event_venues->item(0)->nodeValue;

$bookpaths = $book-


getElementsByTagName( "running_period_of_event" );


foreach( $bookpaths as $bookpath )
{

$start_days= $bookpath->getElementsByTagName( "start_day" );
$start_day= $start_days->item(0)->nodeValue;


$start_months= $bookpath-

getElementsByTagName( "start_month" );


$start_month= $start_months->item(0)->nodeValue;

$start_years= $bookpath-

getElementsByTagName( "start_year" );


$start_year= $start_years->item(0)->nodeValue;

$end_days= $bookpath->getElementsByTagName( "end_day" );
$end_day= $end_days->item(0)->nodeValue;


$end_months= $bookpath->getElementsByTagName( "end_month" );
$end_month= $end_months->item(0)->nodeValue;


$end_years= $bookpath->getElementsByTagName( "end_year" );
$end_year= $end_years->item(0)->nodeValue;
}


//start build... for each


if ($start_month == $getmonth) {


echo "<tr>";


if (($icount) == 1) {
$tablecolour = "<td bgcolor='#CCCCCC'>";
$icount = "0";
} else {
$tablecolour = "<td bgcolor='#FFFFFF'>";
$icount = 1;
}


echo $tablecolour
."<a href='http://www.visitbirmingham.com/exec/
103657/31676/pno=".
$product_no
.",pcode=".$product_code
."' target='_blank'>".$product_name."</a><br>"
."<strong>".$event_venue."&nbsp;</strong></td>"
.$tablecolour
.$start_day."&nbsp;"
.$start_month."&nbsp;-&nbsp;"
.$end_day."&nbsp;"
.$end_month."&nbsp;"
.$end_year."</td></tr>"/n;



}


$start_day = "";
$start_month = "";
$start_year ="";
$end_day = "";
$end_month ="";
$end_year="";
$event_venue="";
$product_name="";
$product_code="";
$product_no="";

}
echo "</table>";


makexmltree("July");


?>


XML File (trimed down)


<dataroot>


<event><product_no>10790</product_no>
<product_code>GBMBL6295E</product_code>
<product_name>Gwen Stefani</product_name>
<running_period_of_event>
<start_day>25</start_day>
<start_month>September</start_month>
<start_year>2007</start_year>
<end_day>25</end_day>
<end_month>September</end_month>
<end_year>2007</end_year>
</running_period_of_event>
<event_venue>The nia academy</event_venue>
</event>


<event>
<product_no>3027</product_no>
<product_code>GBMBL0329E</product_code>
<product_name>Berlioz Restaurant</product_name>
<running_period_of_event>
<start_day>10</start_day>
<start_month>May</start_month>
<start_year>2006</start_year>
<end_day>10</end_day>
<end_month>May</end_month>
<end_year>2010</end_year>
</running_period_of_event>
<event_venue></event_venue>


</event>
</dataroot>
 
P

Pavel Lepin

(e-mail address removed) <[email protected]>
wrote in
Hello I need to get PHP to order the output of the XML
file to be ACENDING to the numerical value of the XML
<start_day></start_day> tags

<?php
function makexmltree($getmonth) {

Oh great. At least there's no BOM.
$product_codes = $book-
getElementsByTagName( "product_code" );
Right.

[...]

makexmltree("July");

?>

XML File (trimed down)

<dataroot>
<event><product_no>10790</product_no>
<product_code>GBMBL6295E</product_code>
<product_name>Gwen Stefani</product_name>
<running_period_of_event>
<start_day>25</start_day>
<start_month>September</start_month>
<start_year>2007</start_year>
<end_day>25</end_day>
<end_month>September</end_month>
<end_year>2007</end_year>
</running_period_of_event>
<event_venue>The nia academy</event_venue>
</event>
<event>
<product_no>3027</product_no>
<product_code>GBMBL0329E</product_code>
<product_name>Berlioz Restaurant</product_name>
<running_period_of_event>
<start_day>10</start_day>
<start_month>May</start_month>
<start_year>2006</start_year>
<end_day>10</end_day>
<end_month>May</end_month>
<end_year>2010</end_year>
</running_period_of_event>
<event_venue></event_venue>
</event>
</dataroot>

Right. Where's the friggin' July? Sorting just one item
simply ain't all that useful either.

Anyway, after spending twenty minutes on getting your code
to work (I got wondering just how messed-up an online
request for help may get... boy, wasn't I surprised), I
have two recommendations for you:

1. Quit now. End your suffering. More importantly, end your
co-workers' suffering. With your lack of mental discipline
and common sense you're not going to do much good, but you
have the potential for causing an awful lot of harm.

2. Barring that, look up usort() in the friggin' PHP Manual.
(Right, it was under your nose all along - does that feel
good?)

HTH, HAND.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top