0

I have set up a jquery autocomplete using a php file to get my data from a database and parse it to json. The problem is when I start typing the name of the employee I am getting the entire list of names not just the employee. Here is my code below.

 <script type="text/javascript">
  $(function(){
    $("#employee").autocomplete({
        source:"allemployeesjson.php",
        minLength:1
    });
   });
 </script>
</head>
<body>
  <div>
    <label for="employee">Employee:</label>
    <input id="employee" />
</div>
</body>
2
  • Can you show contents of allemployeesjson.php? Depends how you are returning the data.
    – GGio
    May 20, 2014 at 19:30
  • You need to filter in your PHP file, the Autocomplete plugin won't do that if you call an external datasource. Please read the docs. If that is still unclear, please edit your post and show us your PHP files content.
    – Thorsten
    May 20, 2014 at 20:00

1 Answer 1

0

I have figured out what the issue was. The original php file was the below file. I had not put a get in it for the data to update.

<?php
session_save_path("../itshear");
session_start();
include('../common.php');
$appquery = "select SSN,cast(rtrim(Lastn)+', '+rtrim(Firstn) as varchar(60))  employee from datatable where mchEmploy = '1' and Persontypeid = '2' order by employee";
$emplist=sqlsrv_query($link,$appquery,array(),array( "Scrollable" => 'static' )) or die('Cannot get employee list');
unset($_SESSION['employees']); 
while ($row = sqlsrv_fetch_array($emplist,SQLSRV_FETCH_ASSOC)) {
    $_SESSION['employees'][]=array('value'=>$row['employee'],'ssn'=>$row['SSN']);
    }
 $_SESSION['json']['employees']= json_encode($_SESSION['employees']);
 echo $_SESSION['json']['employees'];
?>

This is the changed file and it worked fine.

<?php
session_save_path("../itshear");
session_start();
include('../common.php');
$q = $_GET['term'];
if(!$q){return;}
$appquery = "select Mchnum,SSN,cast(rtrim(Lastn)+', '+rtrim(Firstn) as varchar(60))  employee from datatable where mchEmploy = '1' and Persontypeid = '2' and Lastn like '".$q."%' order by employee";
$emplist=sqlsrv_query($link,$appquery,array(),array( "Scrollable" => 'static' )) or die('Cannot get employee list');
unset($_SESSION['employees']); 
while ($row = sqlsrv_fetch_array($emplist,SQLSRV_FETCH_ASSOC)) {
    $_SESSION['employees'][]=array('value'=>$row['employee'],'ssn'=>$row['SSN']);
    }
 $_SESSION['json']['employees']= json_encode($_SESSION['employees']);
 echo $_SESSION['json']['employees'];
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.