You'll need to use some Ajax to search for keywords asynchronously (without reloading the page). You need to create a separate PHP script to process the Ajax request sent from JavaScript. Here's a quick example.
<form id="keywordForm">
<input id="keyword" type="text"/>
<input type="submit" value="Search"/>
</form>
<script>
var form = document.getElementById('keywordForm');
form.addEventListener('submit',function(e) {
var search = form.keyword.value;
var xhr = new XMLHttpRequest();
xhr.open("GET","keywordsearch.php?search="+search,true);
xhr.send();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
var response = xhr.response;
}
}
e.preventDefault();
});
</script>
Then in keywordsearch.php you'd have something like this to except the search parameter sent by a GET request through Ajax then search the database for matching rows.
if(isset($_GET['search'])) {
$pdo = new PDO("mysql:host=localhost;dbname=keywordDB',$user,$pass);
$query = $pdo->prepare("SELECT keyword FROM keywords WHERE keyword LIKE ?");
$query->execute(array($_GET['search']."%"))
$keywords = array();
while($keyword = $query->fetch()) {
$keywords[] = $keyword['keyword'];
}
echo json_encode($keywords);
}