So, I have defined a function for searching from DB and passing the results to ajax.
function do_search() {
$search=$_POST['dname'];
global $wpdb;
$sql="SELECT * FROM employee WHERE `firstname` LIKE '%{$search}%' OR `lastname` LIKE '%{$search}%' OR `department`LIKE '%{$search}%' OR `phone` LIKE '%{$search}%' OR `job_title` LIKE '%{$search}%' OR `cell_phone` LIKE '%{$search}%' OR `image`LIKE '%{$search}%' OR `email` LIKE '%{$search}%' OR `address` LIKE '%{$search}%' OR `room` LIKE '%{$search}%';";
$result2=$wpdb->get_results($sql);
echo json_encode($result2);
wp_die();
}
But my problem is its working only with one word. I tried explode the $_POST value with " ". and then making foreach and build multiple queries, like $query[i] but i cant get no response?
How do implement that when echoing the result - then it echoes result where every word is compared to those field entries?