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
rekha_harnoor
Forum Commoner
Posts: 32 Joined: Mon Feb 19, 2007 3:17 am
Post
by rekha_harnoor » Wed Mar 21, 2007 3:12 am
Hi All,
Following is my code snippet.
I am parsing a xml and displaying. But I want to store 'ProductName', 'PriceFrom', 'PriceTo' to an array of objects and then display it.
How do I do that?
Code: Select all
for($i=0; $i<$res['totalResultsReturned']; $i++) {
foreach($pob->Result[$i] as $key=>$value) {
echo "<a href=\"{$value->Url}\" target=\"blank\" title=\"Learn More at Yahoo.com\">{$value->ProductName}<a>";
echo " Min. Price $" . "{$value->PriceFrom}";
echo " Max. Price $" . "{$value->PriceTo}";
echo "<hr />\n";
}
}
dude81
Forum Regular
Posts: 509 Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City
Post
by dude81 » Wed Mar 21, 2007 3:20 am
Code: Select all
$items_list=array();
for($i=0; $i<$res['totalResultsReturned']; $i++) {
foreach($pob->Result[$i] as $key=>$value) {
echo "<a href=\"{$value->Url}\" target=\"blank\" title=\"Learn More at Yahoo.com\">{$value->ProductName}<a>";
echo " Min. Price $" . "{$value->PriceFrom}";
echo " Max. Price $" . "{$value->PriceTo}";
echo "<hr />\n";
$items_list[$i]['product_name'] = $value->ProductName;
$items_list[$i]['price_from'] = $value->PriceFrom;
$items_list[$i]['price_to'] = $value->PriceTo;
}
}
print_r($items_list);
Hopefully is this what you are expecting??
harrisonad
Forum Contributor
Posts: 288 Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:
Post
by harrisonad » Wed Mar 21, 2007 6:43 pm
you wrote: ...But I want to store 'ProductName', 'PriceFrom', 'PriceTo' to an array of objects and then display it.
adding object to an array is not a big deal. it's just like adding values to an array in a usual way.
Code: Select all
$items = array();
$items[] = new ItemClass($prod_name,$price_from,$price_to);
and displaying it is just like..
i hope that helped