使用php [copy]在文本框中自动提示

This question already has an answer here:

Whenever I input letter 'a' it suggesting all the name with letter 'a' in the name_table. I want to to make it suggest only the name that start with letter 'a'. How to fix this?.

index.php

<html><script type="text/javascript">
$(function() {
    var availableTags = <?php include('autocomplete.php'); ?>;
    $("#first_name").autocomplete({
        source: availableTags,
        autoFocus:true
    });
});
</script>
<form>
<label class="w3-label w3-text-green">Name</label>
<input class="w3-input w3-border" style="height: 30px" type="text" id="first_name" name = "name" required>
</form>
</html>

autocomplete.php

<?php
require('connection.php');
$sql = "select name from employee";
$result = mysqli_query($conn, $sql) or die("Error " .
mysqli_error($connection));

$dname_list = array();
while($row = mysqli_fetch_array($result))
{
$fullname = $row['name'];

$dname_list[] = $fullname;
}
echo json_encode($dname_list);
?>
</div>

I suggest you to use ajax with PHP for getting the autocomplete results on keyup(when some key is pressed and released, JS provides this function).

This is pretty simple and straighforward tutorial on PHP-AJAX-Autocomplete http://papermashup.com/jquery-php-ajax-autosuggest/

In your autocomplete.php file try modifying your query

1.To find the word starting with a

query : SELECT name from employee where name like 'a%'

2.To find the word ending with a

query : SELECT name from employee where name like '%a'

3.To find the word containing a

query : SELECT name from employee where name like '%a%'

You have to use the like operator basically.In sql to match a particular word in your query result we use the below pattern :

%word/lettertosearch%

For more refer to this link : http://www.w3schools.com/sql/sql_like.asp