i am using a function to show and hide div and it's working fine , in one of these divs there is a table , i have a function (php) to search and filter the table and it's a;so working but the problem is when i press the search button(submit in php) the page refreshes (admin.php) showing the first (#pending) . Can i do the php function and stay in the same div(#users without the page refreshing to the begenning. These are the function that i am using:
1-hide and show:
$(function(){
$('#1').on('click',function(){
$('#pending').show();
$('#users').hide();
$('#books').hide();
$('#uploadbook').hide();
});
$('#2').on('click',function(){
$('#users').show();
$('#books').hide();
$('#uploadbook').hide();
$('#pending').hide();
});
$('#3').on('click',function(){
$('#users').hide();
$('#books').show();
$('#uploadbook').hide();
$('#pending').hide();
});
$('#4').on('click',function(){
$('#users').hide();
$('#books').hide();
$('#uploadbook').show();
$('#pending').hide();
});
});
2- refresh div button:
$(document).ready(function(){
$("#search").click(function(){
$("#users").load("/s/admin.php");
});
});
3-search(php):
<?php
require_once 'connection.php';
session_start();
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `r` WHERE CONCAT(`id`, `username`,`email`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `r`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "x");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
I just want to stay where i am after the function is done , and i hope these details are enough for anyone to help me. Thank you.