Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

Assistance needed with code bug

Hi all,

I am having some trouble with some code bug.

Basically I have a UL ... LI list that has an anchor (link) ...and then the link in click I want it to open it's content on the second <UL> that has an id of test ...id="test".

The problem is that when I run the code the 1st item in the list actually works but the rest don't.

Can anyone spot the issue please?

It's driving me crazy :o)

Thanks

Here is the code below attached.




<?php 
					  
					  
$x=$xmlDoc->getElementsByTagName('item');


for ($i=0; $i<=2; $i++)
{
$item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
$item_pubDate=$x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue;
						
						
echo '<li>';
echo '<h3>';
echo '<a id="test" href="'.$item_link.'">"' . $item_title . '"</a>"';
echo $item_desc;
echo '</h3>';
echo '</li>';
						 
						 
						
echo '<ul id="test">'; 
echo '<li>';
echo 'second area';
echo '<div>' . $item_pubDate . '</div>';
echo '<div><h3>' . $item_title . '</h3></div>';
echo '<div>' . $item_desc . '</div>';
echo '</li>';
						 
echo '</ul>';
						 
}
				
?>
			
</ul>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Where is the test data?  From what I can see the $xmlDoc object is undefined.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error77
error77

ASKER

OK, Here is the full source code.

You will see the problem if you run it.

The first link item works and the rest don't.

Thanks again


<html>
<head>
<meta charset="utf-8" /> 
	<title>test</title>
	<link rel="stylesheet"  href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
	<link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
	<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
	<script type="text/javascript" src="docs/docs.js"></script>
	
	
<script type="text/javascript">
function showRSS(str)
{
if (str.length==0)
  {
  document.getElementById("rssOutput").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("rssOutput").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","rss.php?q="+str,true);
xmlhttp.send();
}
</script>


</head>
<body>

<?php
$q="Google";

//$xml=("http://news.google.com/news?ned=us&topic=h&output=rss");

$xml=("http://feeds.bbci.co.uk/news/rss.xml");



$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;

$channel_pubDate = $channel->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue;


?>

<div data-role="page">

	<div data-role="header" data-theme="b">
		<h1>My RSS</h1>
		<a href="../../" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-right jqm-home">Home</a>
	</div><!-- /header -->

	<div data-role="content">

		
<ul data-role="listview">



<?php 


$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++)
  {
  $item_title=$x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
  $item_link=$x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
  $item_desc=$x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
  
  $item_pubDate=$x->item($i)->getElementsByTagName('pubDate')->item(0)->childNodes->item(0)->nodeValue;


  echo '<li>';
  echo '<h3>';
  echo '<a id="test" href="'.$item_link.'">"' . $item_title . '"</a>"';
 
  echo $item_desc;
  echo '</h3>';
  echo '</li>';
 
 

 
 echo '<ul id="test">'; 
 echo '<li>';
 echo 'second area';
 echo '<div>' . $item_pubDate . '</div>';
 echo '<div><h3>' . $item_title . '</h3></div>';
 echo '<div>' . $item_desc . '</div>';
 echo '</li>';
 
 echo '</ul>';
 
  }

?>

</ul>


	</div><!-- /content -->
</div><!-- /page --> 

</body>
</html>

Open in new window

Avatar of error77

ASKER

Anyone please?
Actually, we can't run it because we don't have access to some of the files.  Can you post a link instead where it is actually running?
@error77: You will almost always get better answers if you can isolate a test case that illustrates the problem, and then post the input test data and the expected output that you want to get.  Going forward, you might want to try running your scripts on a live server so you can take advantage of web services like this one:
http://validator.w3.org/