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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.