Phill__Booth Posted July 27, 2007 Share Posted July 27, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/62010-how-to-get-php-to-order-by-day-of-month-when-processing-an-xml-file/ Share on other sites More sharing options...
effigy Posted July 27, 2007 Share Posted July 27, 2007 To my knowledge, DOM only allows you to access the structure, not modify it. I think you need to use xslt_process to pair your XML up with an XSLT. Quote Link to comment https://forums.phpfreaks.com/topic/62010-how-to-get-php-to-order-by-day-of-month-when-processing-an-xml-file/#findComment-308918 Share on other sites More sharing options...
Phill__Booth Posted July 30, 2007 Author Share Posted July 30, 2007 I was hoping I did have to do that as it would have been the long way round but thanks any how! Quote Link to comment https://forums.phpfreaks.com/topic/62010-how-to-get-php-to-order-by-day-of-month-when-processing-an-xml-file/#findComment-310712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.