Maybe I'm barking up the wrong tree. Leatherback, what you suggest is a possibility. What functions do I look into, to go about this?
Here's the code I worked out (thanks to AstroTeg!):
function results() {
//set up SELECT statement
$aSelect = array();
if($_POST['skill'] != '')
$aSelect[] = 'placement_primarytech.PrimaryTechnology';
if($_POST['namefirst'] != '')
$aSelect[] = 'placement_candidate.FirstName';
if($_POST['namelast'] != '')
$aSelect[] = 'placement_candidate.LastName';
if($_POST['region'] != '')
$aSelect[] = 'placement_candidate.Region';
if($_POST['country'] != '')
$aSelect[] = 'placement_candidate.State';
//set up FROM portion of sql statement
$aFrom = array();
if($_POST['skill'] != '')
$aFrom[] = 'placement_primarytech';
if($_POST['namefirst'] || $_POST['namelast'] || $_POST['region'] || $_POST['country'] != '')
$aFrom[] = 'placement_candidate';
//set up WHERE portion of sql statement
$aWhere = array();
if($_POST['skill'] != '')
$aWhere[] = 'placement_primarytech.PrimaryTechnology LIKE "%' . $_POST['skill'] . '%"';
if($_POST['namefirst'] != '')
$aWhere[] = 'placement_candidate.FirstName = "' . $_POST['namefirst'] . '"';
if($_POST['namelast'] != '')
$aWhere[] = 'placement_candidate.LastName = "' . $_POST['namelast'] . '"';
if($_POST['region'] != '')
$aWhere[] = 'placement_candidate.Region = "' . $_POST['region'] . '"';
if($_POST['country'] != '')
$aWhere[] = 'placement_candidate.State = "' . $_POST['end_date'] . '"';
//build SELECT clause
$sSelect = 'SELECT ' . implode(', ', $aSelect);
// build FROM clause
$sFrom = 'FROM ' . implode(', ', $aFrom);
// build where clause
$sWhere = 'WHERE ' . implode(' AND ', $aWhere);
// Select, Where and From clause done - add it to the SQL skeleton
$sql = "" . $sSelect . " " . $sFrom . " ". $sWhere;
echo $sql . "<P>";
$result = mysql_query($sql) or die(mysql_error());
//$num_rows = mysql_num_rows($result);
if($sFrom) {
echo "FROM exists";
}
}
?>
When this function is spit back from a user-inputted form (let's say they enter:
Technology: C
Last Name: Blow
I get this SQL:
SELECT placement_primarytech.PrimaryTechnology, placement_candidate.LastName FROM placement_primarytech, placement_candidate WHERE placement_primarytech.PrimaryTechnology LIKE "%c%" AND placement_candidate.LastName = "blow"
BEAUTIFUL!
Now, I've got to take this query, based on what the user has input, and "drill down". Using the info we have (primarytech = c, lastname = blow), construct a query matching to the appropriate table.
Primarytech exists ONLY? look at candidatetech table now (has candidate IDs with primarytech IDs) and pull up a list of candidates with C programming skills. (further reduced into another function, multipleresults() ).
candidate exists ONLY? (easy, just display candidate info)
Primarytech + candidatelastname? query ok as is.
primarytech + candidatefirstname? query ok as is
candidate firstname and candidate last name? query ok as is
primarytech + state? search in primarytech AND candidate and match 'em up
primarytech + region? search in primarytech AND candidate and match 'em up
region and state? get list of users in these areas
skill and state? search primarytech (C), search candidatetech table where ID = 1 (C technology), take ID from candidatetech table and find those ids in candidate table