AJAX Help needed
I've recently stumbled upon a small issue. Basically I'm trying to give my users the ability to search thru a certain category on my site, but the search is done via AJAX and will not reload the page, simply the content that is being searched through.

The following codes is what I came up with so far, but the only time where it will change something is when there will be no value in the textbox, other than that the content isnt being updated (I checked the PHP file manually and there is no erros & with HTTP Direct addon for Firefox I made sure the call to my php file is made)

My code:

category.php:

        <script type="text/javascript">
    function showCat(str, cat)
    {
    if (str=="")
      {
      document.getElementById("showCategory").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("showCategory").innerHTML=xmlhttp.responseText;
        }
      }
      url="../cat_search.php?q="+str+"&cat="+cat
      
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
    </script>
    <input type="text" name="showCat" onkeyup="showCat(this.value, <?=$id?>)" style="width: 140px;" />

        <div id="showCategory">
         ## Stuff is being listed here on the load of the page & then should be updated with Ajax
        
       </div>

cat_search.php:

    <?php
    include("config.php");
    include("global.php");
    
    $q=$_GET["q"];
    $cat=$_GET["cat"];
    
    $search = $q;
    $q = "%".$q."%";
    
    $sql="SELECT * FROM games WHERE title like '$q' AND category = '$cat'";
    $result = mysql_query($sql);
    
    if(mysql_num_rows($result) == 0) {
    echo "<center><div class=\"redbox\" style=\"width: 110px;\">No match</div></center>";
    }
    
    while($row = mysql_fetch_array($result)) {
    echo '......';
    } ?>

The $id is the actual category ID.

Let me know if you would have the slighest idea of what my problem could be, I use almost the same exact code for another type of search and it works like a charm.

Thanks you!
AJAX Help needed
===

I've recently stumbled upon a small issue. Basically I'm trying to give my users the ability to search thru a certain category on my site, but the search is done via AJAX and will not reload the page, simply the content that is being searched through.

The following codes is what I came up with so far, but the only time where it will change something is when there will be no value in the textbox, other than that the content isnt being updated (I checked the PHP file manually and there is no erros & with HTTP Direct addon for Firefox I made sure the call to my php file is made)

My code:

category.php:

        <script type="text/javascript">
    function showCat(str, cat)
    {
    if (str=="")
      {
      document.getElementById("showCategory").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("showCategory").innerHTML=xmlhttp.responseText;
        }
      }
      url="../cat_search.php?q="+str+"&cat="+cat
      
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }
    </script>
    <input type="text" name="showCat" onkeyup="showCat(this.value, <?=$id?>)" style="width: 140px;" />

        <div id="showCategory">
         ## Stuff is being listed here on the load of the page & then should be updated with Ajax
        
       </div>

cat_search.php:

    <?php
    include("config.php");
    include("global.php");
    
    $q=$_GET["q"];
    $cat=$_GET["cat"];
    
    $search = $q;
    $q = "%".$q."%";
    
    $sql="SELECT * FROM games WHERE title like '$q' AND category = '$cat'";
    $result = mysql_query($sql);
    
    if(mysql_num_rows($result) == 0) {
    echo "<center><div class=\"redbox\" style=\"width: 110px;\">No match</div></center>";
    }
    
    while($row = mysql_fetch_array($result)) {
    echo '......';
    } ?>

The $id is the actual category ID.

Let me know if you would have the slighest idea of what my problem could be, I use almost the same exact code for another type of search and it works like a charm.

Thanks you!