efter din HTML-kode tilføje
<div class="showsearch"></div>
js-kode
$(document).ready(function(){
$('#drop2').on('change',function(){
var fname = $(this).val();
// rename your file which include $fname with get_search_data.php
if(fname !== ""){
$.post('get_search_data.php',{fname: fname},function(data){
$('.showsearch').html(data);
});
}
});
});
- efter den kode skulle den vise $row['fname'] for at showearch div
- du skal inkludere("connection.php"); i get_search_data.php
get_search_data.php
<?php
include("connection.php");
if(isset($_POST['fname'])){
$fname = mysqli_real_escape_string($con, $_POST['fname']);
}
$sql1 = 'SELECT * FROM office WHERE fname LIKE "%'.$fname.'%"';
$result = mysqli_query($con, $sql1);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result)) {
echo $row["fname"]; // this data should appear in showsearch div
}
} else {
echo "0 results";
}
mysqli_close($con);
?>