Hi, after i finished this app i got this problem at the very end. I cannot deliver it now until i solve this, its been a whole day working around this.
Script is online HERE
thanks!
autocomplete.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auto complete demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link type="text/css" rel="stylesheet" href="../admin/themes/redmond.css" />
<script type="text/javascript">
$(function() {
$('#buscar_usuario').autocomplete({
source : 'ajax.php',
select : function(event, ui) {
$('#resultados').html(
'<h2>Detalles de cliente</h2>' + ui.item.value + '<br/>' + ui.item.tel
);
}
});
});
</script>
</head>
<body>
<div id="busqueda">
<input type="text" id="buscar_usuario" name="buscar_usuario" />
</div>
<div id="resultados">
</div>
</body>
</html>
ajax.php
<?
include_once 'clients.class.php';
$usuario = new Usuarios();
echo json_encode($usuario->buscarUsuario($_GET['term']));
?>
clients.class.php
<?
class Usuarios
{
public function __construct() {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'expresscomputerdb';
mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);
}
public function buscarUsuario($nombreusuario) {
$datos = array();
$sql = "SELECT clientname, phone1, id FROM clients WHERE clientname LIKE '%$nombreusuario%'";
$resultado = mysql_query($sql);
while ($row = mysql_fetch_array($resultado, MYSQL_ASSOC)) {
$datos[] = array("value" => $row['clientname'],
"tel" => $row['phone1'],
"company" => $row['companyname'],
"clientid" => $row['id']
);
}
return $datos;
}
}
?>