I cannot for the life of me figure out how to get the logic right on this query:
www.poadocs.com/site/testimonials#review
You can see what I’m trying to do here.
And here’s my query:
$sql = "SELECT doc, joint, sex, testimonial, firstName, lastName, showName FROM $table WHERE $theseDocs && $theseOpSites && $theseSexes ORDER BY doc";
But it isn’t working. When I change the && to OR it works displays results but is incorrect (displays results it shouldn’t).
Here’s how I build my query. I wasn’t sure if I needed the % or not in front of everything but it seems to work both ways:
//which docs selected?
$theseDocs = "(";
for($i = 0; $i < sizeof($doc); $i++) {
if($i > 0) {
$theseDocs .= ' OR ';
}
$theseDocs .= "(doc LIKE '%$doc[$i]%')";
}
$theseDocs .= ")";
//which op sites selected?
$theseOpSites = "(";
$i=0;
for($i = 0; $i < sizeof($opSite); $i++) {
if($i > 0) {
$theseOpSites .= ' OR ';
}
$theseOpSites .= "(joint LIKE '%$opSite[$i]%')";
}
$theseOpSites .= ")";
//which sex?
if($sex == "Both") {
$theseSexes = "sex LIKE '%Male%' OR sex LIKE '%Female%'";
} else if ($sex == "Male") {
$theseSexes = "sex LIKE '%Male%'";
} else {
$theseSexes = "sex LIKE '%Female%'";
}[/QUOTE]