AJAX Question

Associate
Joined
11 May 2007
Posts
531
Location
Over There
Hi all, I would like to pick the brains of this section to see whether they might be able to help with a problem I have:
-A database of products from a business has been created and exported as products.xml

-search.html correctly and successfully sets up the var xmlHttp and references the getproducts.php file

-the AJAX on getproducts.php calls the product_category from the xml but only displays the last item in each category instead of all items from a particular category as intended. Here is the W3Schools tut I was referring to. I have made AJAX front end before which successfully queried an XML document (but including prototype.js to simplify matters), but not in the manner of the tutorial below...and my programming skills have serious gaps unfortunately:

http://www.w3schools.com/PHP/php_ajax_xml.asp

Here is the getproducts.php:
Code:
<?php

$q=$_GET["q"];

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

$x=$xmlDoc->getElementsByTagName("product_category");

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);
    }
  }
}

$product_category=($y->childNodes);

for ($i=0;$i<$product_category->length;$i++)
{
//Process only element nodes
if ($product_category->item($i)->nodeType==1)
  {
 
  echo("<b>" . $product_category->item($i)->nodeName . ":</b> ");
  echo($product_category->item($i)->childNodes->item(0)->nodeValue);
  echo("<br />");
  }
}
?>

Im trying to get this to work as intended but it really needs some interpretation/decoding for me to understand whats going on, particularly lines 10 to 24. Many thanks in advance :)
 
Back
Top Bottom