title: SQL Query: Multiple parameters for 1 column
body: <p>I have these database where I save some activities. This is how they relate with each other.</p>
  
  <pre><code>ACTIVITIES          WEEKDAYS           DAYPARTS
  
  id                  id                 id
  title               weekday            daypart
  daypart_id
  weekday_id 
  </code></pre>
  
  <p>For a filter button, I want to filter the activities on weekdays. So for example, they click on monday, they get all the activities for monday. </p>
  
  <p>The problem is that one column can get multiple parameters, so for example, they can click on monday, but they can also click on tuesday, and wednesday.. and so on. </p>
  
  <p>I try to do that with this code: </p>
  
  <pre><code>public function selectAllActivities($dayparts = false, $weekdays = false){
      $sql = "SELECT `activities`.*, `dayparts`.`daypart`, `weekdays`.`weekday`
      FROM `activities`
      INNER JOIN `dayparts` ON `dayparts`.`id` = `activities`.`daypart_id`
      INNER JOIN `weekdays` ON `weekdays`.`id` = `activities`.`weekday_id`";
  
    if (!empty($dayparts)) {
    $placeHolders = [];        
    foreach ($dayparts as $key =&gt; $daypart) {
        $placeHolders[$key] = ':daypart_id'.$key;
    }
    $sql .= ' AND `daypart` IN ('.implode(', ',$placeHolders).')';
    }
  
    if (!empty($weekdays)) {
      $placeHolders = [];        
      foreach ($weekdays as $key =&gt; $weekday) {
          $placeHoldersB[$key] = ':weekday_id'.$key;
      }
      $sql .= ' AND `weekday` IN ('.implode(', ',$placeHoldersB).')';
      }
  
      $stmt = $this-&gt;pdo-&gt;prepare($sql);
  
    if ($dayparts) {
      foreach ($dayparts as $key =&gt; $daypart) {
          $stmt-&gt;bindValue($placeHolders[$key], $daypart);
        }
    }
    if ($weekdays) {
      foreach ($weekdays as $key =&gt; $weekday) {
          $stmt-&gt;bindValue($placeHoldersB[$key], $weekday);
        }
    }
      $stmt-&gt;execute();
      return $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
    }
  </code></pre>
  
  <p>When I try to filter I get the following error: </p>
  
  <pre><code> Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/INT2_DEV/dao/ActivityDAO.php on line 15
  </code></pre>
  
  <p>There is something wrong with the foreach funtion, but I dont really know what. </p>