Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    xml problem: Notice: Trying to get property of non-object

    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
    PHP Code:
    $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
    PHP 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
    PHP Code:
    $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
    Last edited by LJackson; 06-15-2009 at 06:27 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    its ok the problem seems to lie with my preg_replace
    PHP Code:
    preg_replace("/.{0}(£).*/"""$productPrice); 
    i want it to remove the £ sign at the beginning of the decimal value

    any ideas
    thanks

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok i have solved this now thanks
    used trim instead of preg_replace


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •