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

error77Asked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
And you have the 'ul/li' nested improperly.  The second 'ul' needs to go outside the first 'ul' structure or inside an 'li' but not between elements.
<ul class="first">
<li></li>
<li>
	<ul class="second">
	<li></li>
	<li></li>
	<li></li>
	</ul>
</li>
<li></li>
</ul>

<ul class="third">
<li></li>
<li></li>
<li></li>
</ul>

Open in new window

0
 
Ray PaseurCommented:
Where is the test data?  From what I can see the $xmlDoc object is undefined.
0
 
error77Author Commented:
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

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
error77Author Commented:
Anyone please?
0
 
Dave BaldwinFixer of ProblemsCommented:
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?
0
 
Ray PaseurCommented:
@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/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.