Autocomplete issues in 1.9.1
I used this code in jQuery UI 1.8.18 for autocomplete and it works fairly well.
- $(document).ready(function() {
- $("#cmntclientnameauto").autocomplete({
- minLength: 3,
- source: "ajax/clientlist.php", // Pull in names and addresses
- select: function( e, ui ){ // When we select one
- var keyvalue = ui.item.value;
- $.post("ajax/readclient.php",{id:keyvalue},
- function(data){
- // Pull in the data
- },"json"
- );
- }
- });
- });
This works great I get great looking menu style lists and it selects the info and sends it to readclient.php
Here is clientlist.php to give me the list to select from.
- $term = trim(strip_tags($_GET['term'])); // Need for the jQuery Autocomplete
- // Open the database
- $db = mysql_connect($hostname, $idname, $idpass);
- if (!$db) die(mysql_errno($db).": ".mysql_error($db)."\n");
- mysql_select_db($dbname);
- $sql = "SELECT DISTINCT Last_Name, First_Name, Address1, City, Prov_State, Postal, Client_ID, Phone FROM clients WHERE Last_Name LIKE '".$term."%' AND del_flag = 0 ORDER BY Last_Name";
- $q0 = mysql_query($sql);
- if (!$q0){error_log($sql,0);}
- else {
- $json = '[';
- $first = true;
- while ($row = mysql_fetch_assoc($q0)) {
- if (!$first) { $json .= ','; }
- else { $first = false; }
- $json .= sprintf('{"value":"%s, %s, %s, %s, %s, %s, %d, %s"}',
- $row['Last_Name'], $row['First_Name'], $row['Address1'], $row['City'], $row['Prov_State'], $row['Postal'], $row['Client_ID'], $row['Phone']);
- }
- $json .= ']';
- }
- echo $json;
Like I said it works great to populate the selection menu.
Here is the readclient.php ajax script which reads the selection from above.
- $c = trim(strip_tags($_POST['id']));
- $client = explode(',',$c);
- $cid = $client[6]; // see the Client_ID field in clientlist.php
- // Open the database
- $db = mysql_connect($hostname, $idname, $idpass);
- if (!$db) die("Could NOT connect\n");
- mysql_select_db($dbname);
- $sql = sprintf("SELECT * FROM clients WHERE Client_ID = %d",$flds,$cid);
- $q0 = mysql_query($sql);
- if (!$q0){error_log($sql . ', ' . mysql_errno($db).": ".mysql_error($db),0);}
- else {$row = mysql_fetch_array($q0);}
- echo json_encode($row);
This code also works great. It returns the data record and I populate the form.
No rocket science here!! Almost textbook because I got the code from jQuery autocomplete examples.
Only problem now it doesn't work in 1.9.1. I currently am having extreme issues with 1.9.2 so I can't see if they fixed it.
HELP! I need my autocomplete. I have huge databases!