Welcome to WebmasterWorld Guest from 54.167.175.157

Forum Moderators: httpwebwitch

PHP: How to Sort an Array Through Loop

PHP: How to Sort an Array

   
11:34 am on Aug 18, 2008 (gmt 0)

5+ Year Member



Hello.
I am working on a web page that lists some property stored in an XML
file and I'm having trouble with figuring out how to sort the listings by their "price" element. Currently I pull the "property" elements from the XML into an array and print out the HTML list of property in a non-sorted manner.
I'd like it to print out with a acceding oder for the price followed by a list of property in that price. I'm not sure how to code it though. Any help would be
appreciated. Below is a snippet from the XML file:

<?xml version="1.0" encoding="iso-8859-1" ?>
<ToLet>
<Property>
<Refnumber>21.00</Refnumber>
<Number>34</Number>
<Street>Clifton Road</Street>
<Address3>Newbury Park</Address3>
<Address4>Essex</Address4>
<price>1234</price>
</Property>

<Property>
<Refnumber>22.00</Refnumber>
<Number>54</Number>
<Street>Clifton Road</Street>
<Address3>Newbury Park</Address3>
<Address4>Essex</Address4>
<price>345</price>
</Property>
</ToLet>

12:06 pm on Aug 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi chamara, and welcome to WebmasterWorld!

I suspect that you would be helped by asking this in the PHP Forum [webmasterworld.com], as well as this one.

You can use the PHP SimpleXML [us2.php.net] or the PHP DOMXML [us2.php.net] support to parse and sort the XML, but the printing will probably done through good old-fashioned PHP routines.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month