php - Simplexml count inside a do-while loop -


i trying simplexml count inside do-while loop, yes simple count not correct inside 2 loops. there easier way count?

$query_fl = "select * table"; $fl = mysql_query($query_fl, $rf) or die(mysql_error()); $row_fl = mysql_fetch_assoc($fl);  {     $xml = $row_fl['fu'];     $xmldoc = new domdocument();     $xmldoc->load($xml);      $rss = simplexml_load_file($xml);     $items = $rss->channel->item;      foreach($items $item){         echo $rss->channel->title;         echo $feed_count."<br>";         $feed_count++;     }      $feed_count=1;  } while ($row_fl = mysql_fetch_assoc($fl));  

------------- the output this

feed 1 - count-1 feed 1 - count-2 feed 1 - count-3 feed 1 - count-4 feed 1 - count-5  feed 2 - count- 1 feed 2 - count- 2 feed 2 - count- 3 ... .. 

---------------i want output as

   feed 1 - count-5    feed 2 - count-3 

you should using mysqli instead of mysql_* depricated, moving on... have couple of options, either:

1) move $feed_count=1; before loop single count of items.

or

2) make array of counts foreach loop, incrementing array index each time exit foreach loop. give array of counts items. if use key derived item variable e.g. name, can count number of occurences of item type, if not in xml.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -