Monday, 9 September 2013

how can I make XML print multiple listings?

how can I make XML print multiple listings?

I've got an XML file that is being called by AJAX and it only prints 1
listing of a key while there are multiple listings of that particular key!
here's the link to the XML page -
http://smartliving.comule.com/smartliving.xml
here's the PHP code -
<?php
$q=$_GET["q"];
$xmlDoc = new DOMDocument();
$xmlDoc->load("smartliving.xml");
$x=$xmlDoc->getElementsByTagName('ORIGIN');
for ($i=0; $i<=$x->length-1; $i++)
{
//Process only element nodes
if ($x->item($i)->nodeType==1)
{
if ($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}
$cd=($y->childNodes);
for ($i=0;$i<$cd->length;$i++)
{
//Process only element nodes
if ($cd->item($i)->nodeType==1)
{
echo("<b>" . $cd->item($i)->nodeName . ":</b> ");
echo($cd->item($i)->childNodes->item(0)->nodeValue);
echo("<br>");
}
}
?>
Here's the HTML code to the site as well - URL:
http://smartliving.comule.com/example.html
<html>
<head>
<script>
function showCD(str)
{
if (str=="")
{
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getprod.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="cds" onchange="showCD(this.value)">
<option value="">Select a CD:</optioSelect a CD:
n>
<option value="Thailand">Thailand</option>
<option value="China">China</option>
<option value="India">India</option>
</select>
</form>
<div id="txtHint"><b>CD info will be listed here...</b></div>
</body>
</html>
<!-- Hosting24 Analytics Code -->
<script type="text/javascript"
src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->
if I make a selection - say "Thailand", "India", or "China", it only reads
one product item when it should search through the 250 products that there
are and print out the ones that are manufactured in the respective
countries!
What do you make of this? how can I solve this problem?

No comments:

Post a Comment