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

Discussion in 'XML' started by Phill.Booth@googlemail.com, Jul 27, 2007.

  1. Guest

    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>
    , Jul 27, 2007
    #1
    1. Advertising

  2. Pavel Lepin Guest

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

    --
    ....the pleasure of obedience is pretty thin compared with
    the pleasure of hearing a rotten tomato hit someone in the
    rear end. -- Garrison Keillor
    Pavel Lepin, Jul 30, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Maciejczak
    Replies:
    1
    Views:
    1,970
    Matthias Kaeppler
    Apr 23, 2005
  2. Replies:
    1
    Views:
    434
    Steve W. Jackson
    Dec 22, 2006
  3. Andy
    Replies:
    1
    Views:
    681
  4. Rajive Narain
    Replies:
    0
    Views:
    1,558
    Rajive Narain
    Sep 18, 2009
  5. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    280
    Alex Wayne
    Apr 4, 2008
Loading...

Share This Page