Right, Antonio Laguna is right, but from what I can tell what you need to use is ajax:
http://api.jquery.com/jQuery.ajax/
You”ll have to create a textbox and use the onkeyup event to launch an ajax request, every time the user types a key, to display a php file with the given output from the database (in this file would be the code you had in your question above).
This would look something like this:
index.html:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function typing(search){
$.ajax({
url: 'get_db.php?q='+search,
success: function(data) {
$('#result').html(data);
}
});
}
</script>
</head>
<body>
<input type="textbox" onkeyup="javascript: typing(this.value);">
<div id="results" style="width: 200px; height: 300px;">
</div>
</body>
</html>
get_db.php:
<html>
<head>
</head>
<body>
<ul>
<?php
$typed = $_GET["q"];
$typed = trim($typed);
$query="select * from movies where name="%typed%"";
$rt=mysql_query($query);
echo mysql_error();
while($nt=mysql_fetch_array($rt)){
?>
<li>
<a href="https://stackoverflow.com/questions/10828580/<?php echo"$nthttps://stackoverflow.com/questions/10828580/tag-and-search-system-with-autofill"; ?>"><?php echo "$nt[name]"; ?></a>
</li>
<?php
}
?>
?>
</ul>
</body>
</html>
solved Tag and search system with autofill