OK, here's what I'm doing:
<form method=post action='page.php'>
<input type=text name=searchfield>
<input type=radio name=searchoptions value=val_1> Val 1
<input type=radio name=searchoptions value=val_2> Val 2
<input type=radio name=searchoptions value=val_3 checked> Both Vals
<input type=submit value=Search>
</form>
if ($_POST['searchfield']) {
$sql = "SELECT * FROM table1 WHERE 1 = 1";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_1 LIKE '%".$_POST['searchfield']."%'";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_2 LIKE '%".$_POST['searchfield']."%'";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_3 LIKE '%".$_POST['searchfield']."%'";
if($search = $db->get_results($sql)) {
foreach ( $search as $s )
{
...OUTPUT...
}
}
Above code works for one table. I'd like to be able to do the following:
if ($searchoptions == val_1 ) - search table 1
if ($searchoptions == val_2 ) - search table 2
if ($searchoptions == val_3 ) - search both tables
Afterthought...
Couldn't I just do something like this for running a query on both tables:
$sql = "
(SELECT * FROM table1)
UNION
(SELECT * FROM table2)";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_1 LIKE '%".$_POST['searchfield']."%'";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_2 LIKE '%".$_POST['searchfield']."%'";
$sql .= empty($_POST['searchfield']) ? NULL : " AND val_3 LIKE '%".$_POST['searchfield']."%'";