title: set checkbox codeigniter not populating fields
body: <p>I have a list of sectors that I have retrieved from a database and I am trying to populate only the selected sectors depending on the user. There are 7 sectors (shown below).</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;p class="sector"&gt;&lt;span&gt;North East&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="1" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;City of Sunderland&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="2" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;Sunderland East&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="3" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;Sunderland North&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="4" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;Sunderland West&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="5" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;Coalfield&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="6" /&gt;&lt;/p&gt;
  &lt;p class="sector"&gt;&lt;span&gt;Washington&lt;/span&gt;&lt;input type="checkbox" class="sector-list" name="sector[]" value="7" /&gt;&lt;/p&gt;
  </code></pre>
  
  <p>CONTROLLER:</p>
  
  <pre><code>foreach($data['all_sectors'] as $sectors):
      echo"&lt;p class='service'&gt;&lt;span&gt;$sectors-&gt;sector&lt;/span&gt;&lt;input type='checkbox' class='sector-list' name='sector[]' value='$sectors-&gt;ID' /&gt;&lt;/p&gt;";
  endforeach;
  </code></pre>
  
  <p>Now when the user goes to edit their profile I am trying to pre populate the checkboxes that the user has selected previously. </p>
  
  <p>I am confused as to how I can repopulate the sectors when they created an account. I have tried the following. </p>
  
  <p>CONTROLLER:</p>
  
  <pre><code>$data['assigned_sectors'] = $this-&gt;info_model-&gt;getAssignedSectors();
  
  foreach($data['assigned_sectors'] as $sector) 
      {
          $id_str = array(
              'ID' =&gt; $sector-&gt;sector_ID
          );
      }
      print_r($id_str);
  </code></pre>
  
  <p>Below is the result for '$data['assigned_sectors']'</p>
  
  <pre><code>Array ( [0] =&gt; stdClass Object ( [agency_ID] =&gt; 2 [sector_ID] =&gt; 3 [ID] =&gt; 3 [sector] =&gt; Sunderland East ) [1] =&gt; stdClass Object ( [agency_ID] =&gt; 2 [sector_ID] =&gt; 4 [ID] =&gt; 4 [sector] =&gt; Sunderland North ) )
  </code></pre>
  
  <p>I have tried adding both to the foreach checkbox html but no luck </p>
  
  <pre><code>set_checkbox('sector[]', $data['assigned_sectors']-&gt;sector_ID) //not working
  set_checkbox('sector[]', $id_str-&gt;ID) //not working
  </code></pre>
  
  <p>I am probably overlooking something simple but any help would be greatly appreciated. Thanks!</p>
  
  <p>UPDATE:</p>
  
  <pre><code>$this-&gt;load-&gt;model('admin/info_model');
      $data['agency_sectors'] = $this-&gt;info_model-&gt;getAgencySectors($agency);
  
      $this-&gt;load-&gt;model('admin/agencies_model');
      $data['all_sectors'] = $this-&gt;agencies_model-&gt;getAgencySectors($agency);
  
      echo"&lt;p id='sectors'&gt;&lt;label for='sectors'&gt;Sector&lt;/label&gt;&lt;/p&gt;";
      echo"&lt;div id='sector_list' style='float: left;width: 70%;'&gt;";
      foreach($data['agency_sectors'] as $sector):
          foreach($data['all_sectors'] as $sectors):
          $selected_text = ($sector-&gt;sector_ID === $sectors-&gt;ID) 
             ? " checked='checked'" 
               : '' ;
      echo"&lt;p class='service'&gt;&lt;span&gt;$sectors-&gt;sector&lt;/span&gt;&lt;input type='checkbox' class='sector-list' name='sector[]' value='$sectors-&gt;ID' " . $selected_text . "/&gt;&lt;/p&gt;";
          endforeach;
      endforeach;
      echo"&lt;/div&gt;";
  </code></pre>
  
  <p>If there are 2 agency sectors selected out of the 7 it duplicates the list twice, same for 3 results and so forth</p>