title: Populate Checkboxes on Edit Form
body: <p>I have an edit page that gets populated when accessed. The input values work fine, but I'm having a hard time ticking the category checkboxes. I get the information from two tables. One that displays all the categories and the other one that gets the categories associated with the item.</p>
  
  <p>The following code doesn't work because the second while statement finishes its loop in the first round. Is there an appropriate way to do this?</p>
  
  <pre><code>&lt;?php $check_cats = mysql_query("SELECT * FROM item_categories WHERE itemid = '$itemid'") or die(mysql_error()); ?&gt;
  &lt;?php $result = mysql_query("SELECT * FROM categories ORDER BY cname") or die(mysql_error()); ?&gt;
  
  &lt;?php while($row = mysql_fetch_array( $result )) { ?&gt;
      &lt;input type="checkbox" id="&lt;?php echo $row['cname']; ?&gt;" name="cat[]" value="&lt;?php echo $row['id']; ?&gt;" 
  &lt;?php while($check_cat_rows = mysql_fetch_array( $check_cats )) {
      if ($check_cat_rows['catid'] == $row['id']) {
        echo 'checked="yes"';
      }
    }
  } ?&gt;
  </code></pre>
  
  <p>My Two tables:</p>
  
  <pre><code>TABLE `item_categories`
    `id`
    `itemid`
    `catid`
  
  TABLE `categories`
    `id`
    `cname`
  </code></pre>