使用复选框,php从数据库中搜索和检索多个值

I have 3 column in my database as bodybuild, ethnictype and skincolor in table accounts. I need to search all the three columns at a time to fetch values from it using check boxesthese is my view.

<h4 style="margin-left: 10px; color: gray;">Body Build Types</h4><ol><input type="checkbox" name="bodybuild[]" value="1" />Six Pack<br><input type="checkbox" name="bodybuild[]" value="2" />Fat<br><input type="checkbox" name="bodybuild[]" value="3" />Thin<br></ol><h4  style="margin-left: 10px; color: gray;">Ethnic Types</h4><ol><input type="checkbox" name="ethnictype[]" value="4" />Arab<br><input type="checkbox" name="ethnictype[]" value="5" />Indian<br></ol><h4  style="margin-left: 10px; color: gray;">Skin Color Types</h4><ol><input type="checkbox" name="skincolor[]" value="6" />Black<br><input type="checkbox" name="skincolor[]" value="7" />White<br></ol><input style="margin-left: 10px" type="submit" value='Search' /><br><br><input type="hidden" name="tab1" value="search"></form>

Column bodybuild contain 3 values as 1, 2 and 3

Column ethnictype contain 2 values as 4 and 5

Colum skincolor contain 2 values as 6 and 7

I want to pass the values selcted in check boxes from view page into url like this

/search/1&2&3&4&5&6&7 - when selecting all check boxes and

/search/1&4&6 - when selecting three values (1,4,6) or any other ways.

I can fetch single values from table (as /search/1) but not multiple values.

Please help. Thank you!!!

At last with the help of AJAX I got the solutions to my question. Thanks to all of them who had supported me. Iam posting the code for further candidates.

index.php

<body>
<h1>Demo</h1>
<table id="employees"><thead>
<tr><th>Name</th>
<th>BodyBuild</th>
<th>EthnicType</th>
<th>Skincolor</th></tr>
</thead><tbody></tbody>
</table>
<div id="filter">
<h2>Filter options</h2>
<div>
<h4>Body Build</h4>
<input type="checkbox" id="car" name="sixpack">
<label for="car">Six Pack</label>
</div>
<div>
<input type="checkbox" id="car" name="fat">
<label for="car">Fat</label>
</div>
<div>
<input type="checkbox" id="car" name="thin">
<label for="car">Thin</label>
</div>
<div>
<h4>Ethnic Type</h4>
<input type="checkbox" id="language" name="arab">
<label for="language">Arab</label>
</div>
<div>
<input type="checkbox" id="language" name="indian">
<label for="language">Indian</label>
</div>
<div>
<h4>Skin Color</h4>
<input type="checkbox" id="nights" name="black">
<label for="nights">Black</label>
</div>
<div>
<input type="checkbox" id="nights" name="white">
<label for="nights">White</label>
</div>
</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function makeTable(data){
var tbl_body = "";
$.each(data, function() {
var tbl_row = "";
$.each(this, function(k , v) {
tbl_row += "<td>"+v+"</td>";
})
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
}
function getEmployeeFilterOptions(){
var opts = [];
$checkboxes.each(function(){
if(this.checked){
opts.push(this.name);
}
});
return opts;
}
function updateEmployees(opts){
$.ajax({
type: "POST",
url: "search",
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
updateEmployees();
</script>
</body>

search.php

<?php
$pdo = new PDO('mysql:host=localhost;dbname=castingkall', 'root', '');
$select = 'SELECT name,bodybuild,ethnictype,skincolor';
$from = ' FROM accounts';
$where = ' WHERE TRUE';
$opts = isset($_POST['filterOpts'])? $_POST['filterOpts'] : array('');
if (in_array("sixpack", $opts)){
$where .= " AND bodybuild = 1";
}
if (in_array("fat", $opts)){
$where .= " AND bodybuild = 2";
}
if (in_array("thin", $opts)){
$where .= " AND bodybuild = 3";
}
if (in_array("arab", $opts)){
$where .= " AND ethnictype = 4";
}
if (in_array("indian", $opts)){
$where .= " AND ethnictype = 5";
}
if (in_array("black", $opts)){
$where .= " AND skincolor = 6";
}
if (in_array("white", $opts)){
$where .= " AND skincolor = 7";
}
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);
?>

Just change the database name, table name, column name and values according to your data.

Hope you find this useful