I am in the process of developing an AJAX/PHP based combo box that looks up tersm froma table when you type stuff in a box:
see example below
http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html
<?php
/*
note:
this is just a static test version using a hard-coded countries array.
normally you would be populating the array out of a database
the returned xml has the following structure
<results>
<rs>foo</rs>
<rs>bar</rs>
</results>
*/
$aCountries = array(
"Afghanistan",
"Albania",
"Algeria",
"Andorra",
"Zimbabwe"
);
$input = strtolower( $_GET['input'] );
$len = strlen($input);
$aResults = array();
if ($len)
{
for ($i=0;$i<count($aCountries);$i++)
{
if (strtolower(substr($aCountries[$i],0,$len)) == $input)
$aResults[] = $aCountries[$i];
}
}
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<results>";
for ($i=0;$i<count($aResults);$i++)
echo" <rs>".$aResults[$i]."</rs>";
echo "
</results>
";
?>
Now this works fine but I do not know for sure how to populate the array out of a database instead of hard coding it. I would also like to have it so when the term is found you click submit and bobs your uncle a query displaying the term you chose occurs.
My table is called 'jargon'. I was thinking aobut it and i think a query like this is a good start but then i get stuck
list the jargon terms as you type
$sql = "SELECT * FROM jargon ORDER by jargonterm";
$result = mysql_query($sql) or die("Error fetching array: ".mysql_error());
$array = mysql_fetch_assoc($result);
while ($row = mysql_fetch_assoc($result))
{
click submit and display term:
if (isset($_GET['letter'])) {
include("connect.php");
$course = mysql_real_escape_string($_GET['letter']);
$sql = "SELECT jargonterm FROM jargon WHERE letter = '$letter'";
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
echo '<a href="jargon_complete_details.php?jargonterm='. urlencode($row[0]) .'">'. $row[0] .'</a><br><br>';
}
}