title: Making checkbox checked by exploding value
body: <p>Man this makes no sense I tried to figure this out for hours and searched all over this site.  In the DB, the user_level is 1,2,3 as a value I imploded. I am displaying checkboxes and I want them to be checked when the value matches what is in the DB.  This worked perfectly when there was only a single value in the DB like 1 or 2 for user_level.  Now with 1,2,3, I simply exploded the value then used in_array() to result a result and if so add the checkbox.  For some reason this don't work, random boxes seem to be checked.  Here is the code:</p>
  
  <pre><code>$sql = "SELECT user_level FROM table";
  $result = query_db($sql);
  $row = mysql_fetch_array($result);
  
  
  $field_names =  array(MEMBER    =&gt; 'Member', 
                VISITOR =&gt; 'Visitor');
  
  
  foreach ( $field_names as $key =&gt; $value )
  {
  
      $thePostIdArray = explode(',', $key);
  
      //print_r($thePostIdArray); // testing output
  
  
      $selected = ( in_array($row['user_level'], $thePostIdArray) ) ? 'checked="checked"' : '';
  
  
      $options .= '&lt;input type="checkbox" name="'.$perm_type.'[]" '.$selected.' value="'.$key.'"&gt; '.$value. ' ';
  
  }
  </code></pre>
  
  <p>The $selected value should output the "checked" value on the correct checkboxes but it is not.  </p>