You're going to want to use AJAX to call a php script from your page and then use the php script to query your database and to echo the results back to the page.
I'm going to use jQuery for this example because it saves a lot of lines, you should check it out if you haven't already.
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
function searchOccupation () {
$.ajax({
url: "searchOccupation.php?search=" + $('#searchTxt').attr('value'),
success: function (data) {
alert(data);
}
});
}
</script>
</head>
<body>
<input type="text" id="searchTxt">
<input type="button" value="Search" id="searchBtn" onclick="searchOccupation()">
</body>
Then your php script (whose name should match that in the "url" field of the ajax call (in this case it should be named "searchOccupation.php") will look like this:
<?php
$searchTxt = $_GET['search'];
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = new mysqli('server', 'user', 'password', 'database');
$sql = "SELECT * FROM tableName WHERE occupation = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param('s', $searchTxt);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
echo $row['firstName']; //This sends data back to the page
}
?>
The echo part of the php script is what sends data back into the "success: function (data)" of the javascript, so echo whichever field you want on the page as above.
Edit: Slightly misunderstood what you meant, ajon's above is probably what you need.