title: Checking checkboxes from database values
body: <p>I post values from check boxes into a database for a user profile. When the user goes to edit his/her profile I want the checkboxes that they selected previously to be checked so they don't lose that info after updating their profile. I have tried many different solutions but with no luck.</p>
  
  <p>The check box values get entered into table name members_teachers into a column called focus and are seperated by a comma for example art,mathematics,dance etc I am not sure how close or far I am away at accomplishing my goal but I greatly appreicate any help or suggestions you can provide. Thank you very  much in advance</p>
  
  <p>My code to try and check the values is</p>
  
  <pre><code>&lt;?php
  $focusQuery = mysql_query("SELECT focus FROM members_teachers WHERE id = $member_id") or die;
  
  while ($new_row = mysql_fetch_assoc($focusQuery)){
  
  $focusRow = $row['focus'];
  
  $focusValue = explode(',', $focusRow);
  
  foreach($focusValue as $newFocus){
  
  //echo $newFocus;
  
  //echo "&lt;br/&gt;";
  
  $result = mysql_query("SELECT focus FROM members_teachers WHERE focus LIKE '%$focusRow%'") or die;
  
  if(mysql_num_rows($result) &gt; $newFocus){
  
  $checked = 'checked="checked"';
  
  }
  
  else{
  
  $checked = '';
  
  }
  
  }
  
  }
  ?&gt;
  </code></pre>
  
  <p>This is my html</p>
  
  <pre><code>&lt;label for="art-focus"&gt;Art&lt;/label&gt;
                          &lt;input name="focus[]" type="checkbox" value="Art" &lt;?php echo $checked ?&gt;&gt;
  
  &lt;label for="math-focus"&gt;Mathematics&lt;/label&gt;
                              &lt;input name="focus[]" type="checkbox" value="Mathematics" &lt;?php echo $checked ?&gt;&gt;
  
  &lt;label for="dance-focus"&gt;Dance&lt;/label&gt;
                              &lt;input name="focus[]" type="checkbox" value="Dance" &lt;?php echo $checked ?&gt;&gt;
  </code></pre>