I have a simple question regarding structuring MySQLi Querys with multiple inputs for the same Table Column. Basically, I want people to be able to show results for (1) and (2) vs. (1 and 2), but I keep running into issues.
HTML:
<form method="get" action="page.php">
<ul>
<li><input type="checkbox" name="PT1" value="Condo">Condo</li>
<li><input type="checkbox" name="PT2" value="Single Family">Single Family</li>
</ul>
</form>
PHP:
if($_GET['PT1'] == "Condo") {
$PropType1 = "(property_type = 'Condo') AND ";
}
if($_GET['PT2'] == "Single Family") {
$PropType2 = "(property_type = 'Single Family') AND ";
}
$setPropType = $PropType1 . $PropType2;
MySQLi Statement:
$customSelectSQL = "SELECT * FROM $listingsTable WHERE $setPropType (listing_active = 'yes')";
I'm having a problem where if they're BOTH checked, the query does nothing and I get zero results. But when they're individually selected it works great.
I think what's happening is the database is searching for Properties that equal both inputs, as opposed to equaling each input separately and returning each row for each separate input. Make sense?
I'm guessing it's a matter of encapsulation or something, but when I search for "MySQL SELECT Multiple" or "MySQLi encapsulation", I get a bunch of not-so-helpful examples.
Thanks in advance!