开发者

Xml foreach loop with lots of records, limit records pulled by category and number

$feed = 'myfeed';

$xml = simplexml_load_file($feed);

foreach( $xml->productinfo as $productinfo )
{
$product_category = $productinfo->category;
$product_description = $productinfo->description;

now i inserv each product categor and description into my table.
}

I'm storing the products data, category 开发者_JS百科and description in my database.

Problem is the feed has about 5000 products, in 10 categories. I don't neet to get hundreds of products for each category, I just need about 50. How can I limit the foreach loop, so when for example it loops through 50 tv's, stops and loops through 50 microwaves... and so on.

Any ideeas?

Ty!


ok,if i unserstood it correct you need something like this :

$feed = 'myfeed';

$xml = simplexml_load_file($feed);

foreach( $xml->productinfo as $productinfo )
{
  $product_category = $productinfo->category;
  $$product_category++;
  if($$product_category>50) continue;
  $product_description = $productinfo->description;

//now i inserv each product categor and description into my table.
}

so if you have a product_category lets say tv :

$product_category='tv';
$$product_category=$tv;

and if you have a product_category lets say microwave :

$product_category='microwave';
$$product_category=$microwave;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜