Sort SimpleXml Output by price

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roberts7
Forum Newbie
Posts: 1
Joined: Tue Nov 24, 2009 11:39 am

Sort SimpleXml Output by price

Post by roberts7 »

Hi,

i'm I'm trying to pull products from two xml feeds(like a feed mashup or something).
What i already achieved is to parse the feed and display them correctly, but i can only show one feed results at a time.

My questions would be: How to show the results from both feeds at a time and sort products by the string price.
Mybe it's wrong that i'm using the same variable names( $xml, $items)..

Here are the two codes i'm using:

Code: Select all

$xml = simplexml_load_file('cars.xml.php');
foreach ($xml as $item) {
        $link  = $item->link
        $title = $item->product-name;
        $price = $item->formatted-price;
        $output .="<div><a href=\"$link\"> $title</a></br>Price:$price</div>";
}
 
$xml = simplexml_load_file('trucks.xml.php');
foreach ($xml as $item) {
        $link  = $item->buyurl;
        $title = $item->name;
        $price = $item->price;
        $output .="<div><a href=\"$link\"> $title</a></br>Price:$price</div>";
}
 

Thanks in advance.
Post Reply