nach Ihrem HTML-Code hinzufügen
<div class="showsearch"></div>
js-Code
$(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);
});
}
});
});
- nach diesem Code sollte $row['fname'] für showsearch div angezeigt werden
- Sie müssen include("connection.php"); in 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);
?>