Hello guys, I'm having a problem and hope that you can help me with this.

A little background info.

I use pdo and mysql. I have 1 database and 3 tables. A contact table, with contact info and most important a contact_id, an event table, with event name and event_id and a contact_event table, with contact_id and event_id (these will be filled when a contact has joined or participated an event, which means that the contact_event table will hold multiple of the same contact_id's but with a event_id).


My situation is as followed.

I need to make a selection from the database based upon checkboxes checked or text inputs filled.

So a query must be made based upon checkboxes checked or text inputs. The checkboxes are mainly the events, so the query needs to check if the value (id) of the checkbox exists in the contact_event column, then needs to get the contact info linked to that event_id.

The output should be something like (exported to csv, with headers of the column names for the contact info and event names if any returned):

contact_id, contact info, event_name
1, name address, 2(this is the id of the event).


I think that the code should be something like:

PHP Code:
if (isset($_POST['checkbox'])){
     
$query .= "WHERE ";
     foreach(
$_POST['checkbox'] as $key => $value){
         
$query .= "$key = $value";
     } 
And for the text inputs in should be similar.

Any thoughts on this? Am I doing this right?