Guest User

Untitled

a guest
Jan 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. //AutoComplete code in question
  2. $(function() {
  3. var itemcode_ac = {
  4. source: "/webservices/whs_bincodeAC.php",
  5. select: function(event, ui) {
  6. $('#txtBin').val(ui.item.value);
  7. getWhsInfo();
  8. },
  9. minLength: 1
  10. }
  11. $('#txtBin').autocomplete(itemcode_ac);
  12. });
  13.  
  14. <?php
  15. if(isset($_GET["term"]) && !empty($_GET["term"])) {
  16. include_once $_SERVER['DOCUMENT_ROOT'].'/path/to/dbConnect.php';
  17. $term = mysql_real_escape_string(trim($_GET["term"]));
  18. //wildcard appended here for parameterized query (MySqli)
  19. $term .= "%";
  20.  
  21. $query = "SELECT DISTINCT BinCode, ItemCode, ItemName, WhsCode, DataAsOfDate FROM whse_tbl
  22. WHERE BinCode LIKE '$term' or ItemCode LIKE '$term' ORDER BY BinCode LIMIT 0, 10";
  23. $res = mysql_query($query);
  24.  
  25. //This is the debug code I described above
  26. /*if($row = mysql_fetch_assoc($res))
  27. echo json_encode(array(array('value' => "is row")));
  28. else
  29. echo json_encode(array(array('value' => "no row")));
  30. return;*/
  31.  
  32. $matches = array();
  33. while($row = mysql_fetch_assoc($res))
  34. {
  35. $matches[] = array('value' => $row["BinCode"], 'label' => $row["BinCode"].' - '.$row["ItemCode"],
  36. 'name' => $row["ItemName"], 'whscode' => $row["WhsCode"], 'asOfDate' => $row["DataAsOfDate"]);
  37. }
  38.  
  39. echo json_encode($matches);
  40. }
  41. ?>
Add Comment
Please, Sign In to add comment