0

Here is my code

<div>
    <label for="dynamicSearch">Search:</label>
    <input id="dynamicSearch">
</div>

$(function () {
 // autocomplete
    $("#dynamicSearch").autocomplete({
        source: "dynamicSearch.php",
        minLength: 1
    });
});

dynamicSearch.php

<?php
$con = pg_connect("connection");
if (!$con)
  {
  die("Could not connect: " . pg_last_error());
  }

  $dynamicSearch = "SELECT name from bkash_dist WHERE name LIKE '%".$_GET['term']."%' LIMIT 10";

  $result = pg_query($con, $dynamicSearch);



    while($row = pg_fetch_array($result))
      {      
            $results[] = array('label' => $row['distrbutor']);
            }



pg_close($con);
$encoded = json_encode($results); 

// send response back to index.html
// and end script execution
die($encoded)
?>

When I am searching with "A" its giving all result those contains "A" but I want those start with "A" or "a" (case sensitive). How can I do it?

4

2 回答 2

3

只需更改SQL 查询,使其仅查找结果的开头:

$dynamicSearch = "SELECT name from bkash_dist 
                  WHERE name
                  LIKE '"$_GET['term']."%'
                  LIMIT 10";
于 2013-05-21T11:30:55.727 回答
1

你的dynamicSearch.php 中有什么?

查看文档中的这个示例。它完全符合您的要求

于 2013-05-21T10:52:30.020 回答