> -----Original Message----- > From: Justin Patrin [mailto:[EMAIL PROTECTED] > Sent: Sunday, December 14, 2003 2:51 AM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] Sorting arrays > > > Jake McHenry wrote: > > >>-----Original Message----- > >>From: Bronislav Klucka [mailto:[EMAIL PROTECTED] > >>Sent: Sunday, December 14, 2003 1:52 AM > >>To: Jake McHenry; 'Php-general' > >>Subject: RE: [PHP] Sorting arrays > >> > >> > >>Try to explain a little bit more how the arrays could be > >>sorted asscending and by hitting back and submitting form > >>suddnely sorted descending... > >> > >> > >>Brona > >> > >> > >>>Does anyone know of a way to keep sort from reversing the > >> > >>array order? > >> > >>>That is kinda fuzzy, let me explain. > >>> > >>>I have a couple arrays that I am sorting. If the user hits the > > > > back > > > >>>button in their browser, and hits submit again without changing > >>>anything, the array is sorted again, now in decending order > >> > >>instead of > >> > >>>ascending as it was the first time around. > >>> > >>>The arrays contain dates, and I want them in ascending order. > >>> > >>>Is there a way to limit any of the sort routines to ascending > > > > only? > > > >>>Thanks, > >>> > >>>Jake McHenry > >>>Nittany Travel MIS Coordinator > >>>http://www.nittanytravel.com > >>> > >>>-- > >>>PHP General Mailing List (http://www.php.net/) > >>>To unsubscribe, visit: http://www.php.net/unsub.php > >>> > >> > > > > This page is for adding / editing / removing airline reservations.
> > What I have done so far is when the user first gets to this > specific > > page, they enter their info. If they put a check in the add next > > flight checkbox, then the same form comes up again, each > time adding > > the new info to the same array, building upon the old info. > The arrays > > are then displayed back into form fields where the user can > edit any > > info submitted. > > > > I'm sorting the arrays by the flight dates. Each time the > user enters > > a new flight, the array is sorted by date. This is where I'm seeing > > the problem. The first flight is fine, of course. The > second is fine. > > The third flight entered and all of the flights are now in reverse > > order. Then the next flight entered, they're all in the > correct order, > > etc, etc. > > > > This problem will most likely happen to my other arrays > further on in > > the project. > > > > Is there any way I can make sure that the dates are always in the > > correct order? > > > > > > > > Thanks, > > > > Jake McHenry > > Nittany Travel MIS Coordinator > > http://www.nittanytravel.com > > This is very strange. sort() ALWAYS sorts the same way when > you call it > the same way, period. Perhaps you're not sorting on the correct data? > Could you please show us exactly what your arrays look like, > which sort > function you are using, and how you're calling it? > > -- > paperCrane <Justin Patrin> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > I just tried switching to natsort and it still does the same thing. I just posted the array structure, here they are again: First time natsort($array) returns Array ( [0] => 02-11-2004|Salt Lake|UT|Wilkes-Barre|PA||No|No [1] => 01-23-2004|Salem|WA|Wilkes-Barre|PA||No|No [2] => 01-08-2004|Denver|CO|Wilkes-Barre|PA||No|No [3] => 01-02-2004|Wilkes-Barre|PA|Denver|CO||Yes|Yes [4] => 01-16-2004|Wilkes-Barre|PA|Salem|WA||Yes|Yes [5] => 01-30-2004|Wilkes-Barre|PA|Salt Lake|UT||Yes|Yes ) Second time natsort($array) returns Array ( [0] => 01-30-2004|Wilkes-Barre|PA|Salt Lake|UT||Yes|Yes [1] => 01-16-2004|Wilkes-Barre|PA|Salem|WA||Yes|Yes [2] => 01-02-2004|Wilkes-Barre|PA|Denver|CO||Yes|Yes [3] => 01-08-2004|Denver|CO|Wilkes-Barre|PA||No|No [4] => 01-23-2004|Salem|WA|Wilkes-Barre|PA||No|No [5] => 02-11-2004|Salt Lake|UT|Wilkes-Barre|PA||No|No ) Nothing has changed in the array, but the order. Why does this stuff always happen to me? lol Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php