01-17-2017, 02:21 PM
The first thing that stands out is that you're replacing your queries. So, for instance in this section...
if both children and something are selected, it will fire off the something query (using the $compQ variable) and get the results with the $comp variable and then once it sees that children are selected, it will flush out those two variables with the results from children. So give each one its own variable name. I like being super consistent like...
//you could probably just use the $children variable again
Also, since you already have your if statements for each query, you can go ahead and feel free to pop in your foreach there and get rid of the one below. . So that would look like. I would also put in a check here to make sure you got a result. So, what you can do, is count the number of rows you got back. This will stop it from throwing errors in the event you didn't get any results.
//you could probably just use the $children variable again
Code:
if($something == 1){
Code:
//if last name box is checked
Code:
$something = "something";
Code:
$compQ=$db->query("SELECT id FROM users WHERE something = ? ",array($something));
Code:
$comp=$compQ->results();
Code:
}
Code:
if($children == 1){
Code:
//if last name box is checked
Code:
$children = "children";
Code:
$compQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children));
Code:
$comp=$compQ->results();
Code:
}
if both children and something are selected, it will fire off the something query (using the $compQ variable) and get the results with the $comp variable and then once it sees that children are selected, it will flush out those two variables with the results from children. So give each one its own variable name. I like being super consistent like...
Code:
if($children == 1){
Code:
//if last name box is checked
Code:
$children = "children";
Code:
$childrenQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children));
Code:
$childrenR=$childrenQ->results();
Code:
}
Also, since you already have your if statements for each query, you can go ahead and feel free to pop in your foreach there and get rid of the one below. . So that would look like. I would also put in a check here to make sure you got a result. So, what you can do, is count the number of rows you got back. This will stop it from throwing errors in the event you didn't get any results.
Code:
if($children == 1){
Code:
//if last name box is checked
Code:
$children = "children";
Code:
$childrenQ=$db->query("SELECT id FROM users WHERE children = ? ",array($children));
Code:
$childrenC=$childrenQ->count();
Code:
if($childrenC > 0){ //only fire off the rest of this if you got any results from your query
Code:
$childrenR=$childrenQ->results();
Code:
foreach ($childrenR as $c){
Code:
if (!in_array($c, $matches)) {
Code:
array_push($matches,$c);
Code:
}
Code:
}
Code:
}
Code:
}