I'm trying to build a search function that will search all columns in a table. Here is what I've got:
if (isset($_POST['submitted'])) {
$q = "SELECT * FROM children ";
if(isset($_POST['query'])) {
$q .= "WHERE ";
$all = "SELECT * FROM children WHERE 1";
$r_all = mysqli_query($dbc, $all);
while ($field = $r_all->fetch_field()) { // Get field headers for building query
$f_name = "{$field->name} LIKE {$_POST['query']},:"; // Build query with search string
$fn = explode(":",$f_name); // Need to convert $f_name to an array but this does not convert it to a single array but multiple arrays
$q .= implode("OR", $fn); // Need to insert OR for the db query
} // End while ($field = $r_all->fetch_field())
} // End if(isset($_POST['query']))
} // End if (isset($_POST['submitted']))
The explode function is what is not working for me. It gives me this (sam is the search string I entered into the form):
Array ( [0] => child_id LIKE sam, [1] => ) Array ( [0] => first_name LIKE sam, [1] => ) Array ( [0] => second_name LIKE sam, [1] => ) Array ( [0] => last_name1 LIKE sam, [1] => ) Array ( [0] => last_name2 LIKE sam, [1] => ) Array ( [0] => gender LIKE sam, [1] => ) Array ( [0] => dob LIKE sam, [1] => )
so instead of getting one array with each string being a value I get multiple arrays. Any ideas?