jcanker Posted February 13, 2011 Share Posted February 13, 2011 I've set up a php page to process my customers by customer name and the business code which references the account (busname, buscode). It's pulled from MySQL using ORDER BY busname ASC. When I run the php on it's own, the xml is echoed properly and they all appear in alphabetical order. I'm using this jquery function to process the xml: function getCustomerList() { //this code modeled after tutorial at: http://think2loud.com/reading-xml-with-jquery/ $.ajax({ type: "POST", url: "php/selectcustomer.php", dataType: "xml", success: function(xml) { $(xml).find('Customer').each(function(){ var buscode = $(this).find('buscode').text();//this refers to the current Customer var busname = $(this).find('busname').text(); var selectlist = '</BR>'+buscode+'</br>'+busname+'</hr>'; $('#rightColumn').prepend(selectlist); }); } }); } The function is called inside document.ready so it runs when the page loads. This code adds the list to the top of #rightColumn as expected, but the list is ordered in reverse alpha-order. The easy fix is just to reverse sort on the php side, but I'd like to understand why it's doing it so I understand jQuery better since I'm just learning it. Link to comment https://forums.phpfreaks.com/topic/227502-jquery-processing-xml-in-reverse-alpha-order/ Share on other sites More sharing options...
jcanker Posted February 13, 2011 Author Share Posted February 13, 2011 I solved my own problem-- The act of prepending is inside the foreach loop, so as it goes through the list it places each item at the top of the list. End result: Reverse Alpha Order. Link to comment https://forums.phpfreaks.com/topic/227502-jquery-processing-xml-in-reverse-alpha-order/#findComment-1173478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.