...

View Full Version : Autosuggest/SQL query works sometimes



soneen
12-08-2010, 07:59 AM
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?


$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>";

soneen
12-08-2010, 06:55 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum