Jump to content

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


Recommended Posts

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." </strong></td>"

.$tablecolour

.$start_day." "

.$start_month." - "

.$end_day." "

.$end_month." "

.$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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.