LJackson
06-15-2009, 05:21 PM
Hi All,
ok i have been displaying the contents of an xml document on my site with no problem
i have now decided to add the data into my db first so that i can sort multiple xml files.
anyway here is what i had before
$request = "http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AssociateTag=kernconn-21&AWSAccessKeyId=AKIAJG6R2QHMH3HXDOTA&Operation=ItemSearch&Version=2007-07-16&SearchIndex=$SearchIndex&Keywords=$Keywords&ResponseGroup=ItemAttributes,Offers";
//echo $item->ItemAttributes->Title;
$obj = simplexml_load_file($request);
$count = 1;
foreach($obj->Items->Item as $item){
<div class="prices_store">Amazon.co.uk</div>
<div class="prices_rating">store rating</div>
<div class="prices_price"><?php echo $item->Offers->Offer->OfferListing->Price->FormattedPrice;?></div>
<div class="prices_delivery">-</div>
<div class="prices_total">-</div>
<div class="prices_visit"><?php echo "<a href='{$item->DetailPageURL}'>Link</a>";?></div>
<?php
//echo $item->Offers->Offer->OfferListing->PercentageSaved;
}
$count ++;
}
which worked
and here is my new code
$request = "http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AssociateTag=kernconn-21&AWSAccessKeyId=AKIAJG6R2QHMH3HXDOTA&Operation=ItemSearch&Version=2007-07-16&SearchIndex=VideoGames&Keywords=wii&ResponseGroup=ItemAttributes,Offers";
//echo $item->ItemAttributes->Title;
$obj = simplexml_load_file($request);
$count = 1;
foreach($obj->Items->Item as $item){
$merchantname = "Amazon.co.uk";
$productPrice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
$productPrice = preg_replace("/.{0}(£).*/", "", $productPrice);
$PnP = "";
$totalPrice = "";
$link = $item->DetailPageURL;
if ($count <= 1){
$getpricesSQL = "INSERT INTO comparison_results
(storeID,product_price,postage_price,total_price,link)
VALUES('$merchantname','$productPrice','$PnP','$totalPrice',
'$link')";
$query = mysql_query($getpricesSQL)or die(mysql_error());
//echo $item->Offers->Offer->OfferListing->PercentageSaved;
}
$count ++;
}
?>
but im now getting
Notice: Trying to get property of non-object on line 224 which is
$productPrice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
the sql doesnt throw up any errors and it inserts the merchantname and the link but not the prices?
any ideas how i can fix this?
Thanks
Luke
ok i have been displaying the contents of an xml document on my site with no problem
i have now decided to add the data into my db first so that i can sort multiple xml files.
anyway here is what i had before
$request = "http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AssociateTag=kernconn-21&AWSAccessKeyId=AKIAJG6R2QHMH3HXDOTA&Operation=ItemSearch&Version=2007-07-16&SearchIndex=$SearchIndex&Keywords=$Keywords&ResponseGroup=ItemAttributes,Offers";
//echo $item->ItemAttributes->Title;
$obj = simplexml_load_file($request);
$count = 1;
foreach($obj->Items->Item as $item){
<div class="prices_store">Amazon.co.uk</div>
<div class="prices_rating">store rating</div>
<div class="prices_price"><?php echo $item->Offers->Offer->OfferListing->Price->FormattedPrice;?></div>
<div class="prices_delivery">-</div>
<div class="prices_total">-</div>
<div class="prices_visit"><?php echo "<a href='{$item->DetailPageURL}'>Link</a>";?></div>
<?php
//echo $item->Offers->Offer->OfferListing->PercentageSaved;
}
$count ++;
}
which worked
and here is my new code
$request = "http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AssociateTag=kernconn-21&AWSAccessKeyId=AKIAJG6R2QHMH3HXDOTA&Operation=ItemSearch&Version=2007-07-16&SearchIndex=VideoGames&Keywords=wii&ResponseGroup=ItemAttributes,Offers";
//echo $item->ItemAttributes->Title;
$obj = simplexml_load_file($request);
$count = 1;
foreach($obj->Items->Item as $item){
$merchantname = "Amazon.co.uk";
$productPrice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
$productPrice = preg_replace("/.{0}(£).*/", "", $productPrice);
$PnP = "";
$totalPrice = "";
$link = $item->DetailPageURL;
if ($count <= 1){
$getpricesSQL = "INSERT INTO comparison_results
(storeID,product_price,postage_price,total_price,link)
VALUES('$merchantname','$productPrice','$PnP','$totalPrice',
'$link')";
$query = mysql_query($getpricesSQL)or die(mysql_error());
//echo $item->Offers->Offer->OfferListing->PercentageSaved;
}
$count ++;
}
?>
but im now getting
Notice: Trying to get property of non-object on line 224 which is
$productPrice = $item->Offers->Offer->OfferListing->Price->FormattedPrice;
the sql doesnt throw up any errors and it inserts the merchantname and the link but not the prices?
any ideas how i can fix this?
Thanks
Luke