Ive got an RSS parser using the DOM. Its got a loop to display each item. I want to have a hidden field on each item then post this to another page.

Im having trouble counting each item in the loop. Help please :)

This is what ive got:

<?php
function get_remotetitle($urlpage)
	{
	$dom = new DOMDocument();

	        if($dom->loadHTMLFile($urlpage)) {

	            $list = $dom->getElementsByTagName("title");
	            if ($list->length > 0) {
	                return $list->item(0)->textContent;
	            }
	        }
	}
	
$links = array('feed1','feed2');

foreach($links as $link){
	
$doc = new DOMDocument();
$doc->load($link);
 
$dataset = $doc->getElementsByTagName( "item" );

foreach( $dataset as $row )
{
 
    $xmlEmails = $row->getElementsByTagName( "link" );
    $xmlEmail = $xmlEmails->item(0)->nodeValue;
	$title = get_remotetitle($xmlEmails->item(0)->nodeValue);
 

    echo '<a href="'.$xmlEmail.'">'.$title.'</a><br />';
	echo '<input type="hidden" name="loopnum" value="loopnum">';
}
}

	
?>
$loopnum = 0;
foreach( $dataset as $row ) {
  $xmlEmails = $row->getElementsByTagName( "link" );
  $xmlEmail = $xmlEmails->item(0)->nodeValue;
  $title = get_remotetitle($xmlEmails->item(0)->nodeValue);
  echo '<a href="'.$xmlEmail.'">'.$title.'</a><br />';
  echo "<input type=\"hidden\" name=\"loopnum\" value=\"$loopnum\">";
  $loopnum++;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.