Okay, after a week of work frustration I can now get back to helping you with this. I apologize.
Just for reference, this would be your qualityadmin table:
qualityadmin
qualityadmin_id
quality_name
address1
address2
etc......
Basically, the following tables:
activity_participant
activity_participant_id
activity
expert_participant
expert_participant_id
expert
quality_systems
quality_system_id
quality_system
Will contain the values for each quality system, expertise and activity, each having a title/description and a unique ID. These will be used
for generating our checkboxes dynamically for a user to choose from.
The below tables:
activity_participant_rel
activity_participant_relid
qualityadmin_relid
expert_participant_rel
expert_participant_relid
qualityadmin_relid
quality_system_rel
qualitysystem_relid
qualityadmin_relid
Will contain two values, the ID number of the associated organization and the ID number of the corresponding quality system, expertise and activity.
These values will be compared against for what organizations match the user's search criteria.
Let's now query for all the quality systems, expertise and activities for use in our checkbox arrays:
// Get the quality systems
$sql_qualsys = "SELECT * FROM quality_systems ORDER by quality_system";
$qualsys_result = mysql_query($sql_qualsys) or die("Error fetching quality systems: ".mysql_error());
$qualsys_array = mysql_fetch_assoc($qualsys_result);
// Get the expertise
$sql_expert = "SELECT * FROM expert_participant ORDER by expert";
$expert_result = mysql_query($sql_expert) or die("Error fetching experts: ".mysql_error());
$expert_array = mysql_fetch_assoc($expert_result );
// Get the activities
$sql_activity = "SELECT * FROM activity_participant ORDER by activity";
$activity_result = mysql_query($sql_activity) or die("Error fetching activities: ".mysql_error());
$activity_array = mysql_fetch_assoc($activity_result);
Next, we'll take these arrays and print out a search form:
echo ('<form name="searchform" method="GET" action="search.php">
<table>
<tr>
<td>Select the quality systems:</td>
</tr>
<tr>
<td>');
foreach($qualsys_array as $qualsys){
echo ('<input type="checkbox" name="qualsys_checkbox[]" value="".$qualsys['quality_system_id']."">".$qualsys['quality_system']."');
}
echo ('</td>
</tr>
<tr>
<td>Select the expertise:</td>
</tr>
<tr>
<td>');
foreach($expert_array as $expert){
echo ('<input type="checkbox" name="expert_checkbox[]" value="".$expert['expert_participant_id']."">".$expert['expert']."');
}
echo ('</td>
</tr>
<tr>
<td>Select the activities:</td>
</tr>
<tr>
<td>');
foreach($activity_array as $activity){
echo ('<input type="checkbox" name="activity_checkbox[]" value="".$activity['activity_participant_id']."">".$activity['activity']."');
}
echo ('</td>
</tr>
<tr>
<td>
<input type="submit" name="search_submit" value="Search!">
</td>
</tr>
</table>');
This will get you the basic elements for your search form, dynamically generated from the database. Next, you'll simply need to parse through
the $_GET array for the checkbox values the user chose, and add them to a SQL query:
if($_GET['search_submit']){
// Start the basic query
$sql_admin = "SELECT qa.* FROM quality_admin qa, activity_participant atc, activity_participant_rel act_rel, expert_participant ex,
expert_participant_rel ex_rel, quality_systems qs, quality_system_rel qs_rel
WHERE act_rel.activity_participant_relid = act.activity_participant_id AND act_rel.qualityadmin_relid = qa.quality_admin_id
AND ex_rel.expert_participant_relid = ex.expert_participant_id AND ex_rel.qualityadmin_relid = qa.quality_admin_id
AND qs_rel.quality_system_relid = qs.quality_system_id AND ex_rel.qualityadmin_relid = qa.quality_admin_id
";
// Check the activity checkbox array for passed values, build a query line with them if there are any
if(count($_GET['activity_checkbox']) > 0){
$act_sql_append = "AND act.activity_participant_id IN ('" . implode("','", $_GET['activity_checkbox']) . "')";
$sql_admin .= $act_sql_append;
}
// Check the expert checkbox array for passed values, build a query line with them if there are any
if(count($_GET['expert_checkbox']) > 0){
$ex_sql_append = "AND ex.expert_participant_id IN ('" . implode("','", $_GET['expert_checkbox']) . "')";
$sql_admin .= $ex_sql_append;
}
// Check the quality system checkbox array for passed values, build a query line with them if there are any
if(count($_GET['qualsys_checkbox']) > 0){
$qs_sql_append = "AND qs.quality_system_id IN ('" . implode("','", $_GET['qualsys_checkboxx']) . "')";
$sql_admin .= $qs_sql_append;
}
// Add ordering and grouping to the query, and append them to the query
$sql_group = "GROUP BY qa.qualityadmin_id";
$sql_order = "ORDER BY qa.quality_name";
$sql_admin .= $sql_group . $sql_order;
// Run the query, and fetch the results
$sql_result = mysql_query($sql_admin) or die("Error in search query: ".mysql_error());
$sql_array = mysql_fetch_assoc($sql_result);
//
// Print your results here
//
}
This code is far from perfect, and I'm sure you'll have to do some variable and syntax renaming to ensure that it works for your situation
and SQL tables. Basically this will give you a rundown of a general method of turning form values into search criteria.
Let me know if you have questions on this code, or need further help. I apologize again for the time I took to post, and I hope you find this helpful.