If the values in the select
menus are as disclosed above - ie:integers then I think you could try something like the following assuming I interpreted the question/request correctly.
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
/*
filter the POST values - ensur ethey are integers
*/
$_POST['name']=filter_input( INPUT_POST, 'name', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
$_POST['age']=filter_input( INPUT_POST, 'age', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
$_POST['work']=filter_input( INPUT_POST, 'work', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY );
# base sql query
$sql='select * from `people`';
# arrays to store `like` clauses for each selected option
$a=$b=$c=array();
/*
process all selected options and add to respective array
*/
if( !empty( $_POST['name'] ) ){
foreach( $_POST['name'] as $value ){
if( !empty( $value ) ) $a[]='`name` like "%'.$value.'%"';
}
}
if( !empty( $_POST['age'] ) ){
foreach( $_POST['age'] as $value ){
if( !empty( $value ) ) $b[]='`age` like "%'.$value.'%"';
}
}
if( !empty( $_POST['work'] ) ){
foreach( $_POST['work'] as $value ){
if( !empty( $value ) ) $c[]='`work` like "%'.$value.'%"';
}
}
/*
construct final sql
*/
if( !empty( $a ) or !empty( $b ) or !empty( $c ) ) $sql.=' where ';
if( !empty( $a ) )$sql.= sprintf('( %s )', implode( ' OR ', $a ) );
if( !empty( $b ) )$sql.= ' AND ' . sprintf('( %s )', implode( ' OR ', $b ) );
if( !empty( $c ) )$sql.= ' AND '. sprintf('( %s )', implode( ' OR ', $c ) );
#what you do with it now is up to you...
exit( $sql );
}
?>
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title></title>
<style>
select{width:100px}
</style>
</head>
<body>
<form method='post'>
<select class='selectpicker' name='name[]' multiple data-live-search='true'>
<option value=1>1
<option value=2>2
</select>
<select class='selectpicker' name='age[]' multiple data-live-search='true'>
<option value=1>1
<option value=2>2
</select>
<select class='selectpicker' name='work[]' multiple data-live-search='true'>
<option value=1>1
<option value=2>2
</select>
<input type='submit' />
</form>
</body>
</html>