Jump to content

Need Help: For Each / XML / Please Read


hinchcliffe

Recommended Posts

Hello,

 

I'm currently grabbing data from an XML feed & with this data I'm updating product information in our database. We have over 2500+ products in our database. I'm trying to run a script that will go through and update every products price from the xml feed. My issue is that the xml feed only allows you to pull 50 products at once.

 

So this is where I'm stuck.

 

Right now I have a for each statement that limits to grabbing 50 products.

 

<?php
$i = 0;
foreach ($products as &$value) {

//product update code goes in here

if (++$it == 50) break;
}
?>

 

Is there anyway I can continue where I left off and pull the next 50 products to update? I'm kind of lost.

 

Link to comment
Share on other sites

function next50($page) {

  // this code assumes the xml feed will return no data when there is no more rows to update..

  // get the other 50 and fill into $xml with $page being an int

  if ($xml == null) return;

  foreach ($xml as $v) {

    // parse your XML into $id, $price, $name etc

    $products[$id] = "whatever whatever";

  }

  next50(++$page);

}

next50(1);

 

note its untested, but it should work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.