Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Autosuggest/SQL query works sometimes

    Hello all. I have an autosuggest textfield that has been acting up. The problem is that it only works sometimes. For some entries in the database, just typing the first letter is enough to pull results up (as it should work), but others I have to type two, three, or even the entire word. A few entries won't even come up at all, even when I change the query to "code='$input'". Here is the php. I'm not really sure what could cause this. Should I post the javascript/html?

    PHP Code:
        $input strtoupper($_GET['input']);
        
        
    $aResults = array();
        
        
    $query "SELECT * FROM classList WHERE code LIKE '$input%' LIMIT 10";
        
        
    $result mysqli_query($cxn,$query);
        
        while( 
    $row mysqli_fetch_array($result) )
        {    
        
    $aResults[] = array( "id"=>($row['code']) ,"value"=>($row['code']), "info"=>($row['name']) );
        }
        
        
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    
        
    header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
        
    header ("Cache-Control: no-cache, must-revalidate");
        
    header ("Pragma: no-cache");
        
    header("Content-Type: text/xml");
        
        
                echo 
    "<results>";
                for (
    $i=0;$i<count($aResults);$i++)
                {
                    echo 
    "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
                }
                echo 
    "</results>"

  • #2
    New Coder
    Join Date
    Jun 2010
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts
    FIXED: It was an XML error for the response text. My database was trying to spit out results with "/" in it and the XML wouldn't have it. Added "htmlspecialchars()" around the array results and whalah!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •