我正在嘗試在do-while循環內執行simplexml計數,但它的簡單但計數不正確,因爲它在2個循環內。有一個更簡單的方法來做計數?在do-while循環內執行Simplexml計數
$query_fl = "SELECT * FROM table";
$fl = mysql_query($query_fl, $rf) or die(mysql_error());
$row_fl = mysql_fetch_assoc($fl);
do {
$xml = $row_fl['fu'];
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);
$rss = simplexml_load_file($xml);
$items = $rss->channel->item;
foreach($items as $item){
echo $rss->channel->title;
echo $feed_count."<BR>";
$feed_count++;
}
$feed_count=1;
} while ($row_fl = mysql_fetch_assoc($fl));
------------- 輸出是這樣
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
...
..
--------------- 我想輸出作爲
Feed 1 - Count-5
Feed 2 - Count-3
你可以在你的加載的xml中指定'first_feed'元素嗎?因爲在上面的代碼片段中沒有提及它。如果您提供更多的細節,那麼解決方案可以更加明顯。 – NullPointer 2013-05-09 12:53:37