title: Radio button inside two foreach loops not getting checked
body: <p>My code works like this. If a parent product has two variants, it creates two div (one hidden). When I click on radio button, it shows its relevant div &amp; hides the other.</p>
  
  <p>Now on page load, by default checked property doesn't work on any radio button.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$pid=2;
  foreach($query as $row){
    echo "&lt;div class='$row['id']' &lt;?php if($row['id']!=$pid){ ?&gt;
          style='display:none;' &lt;?php } ?&gt;&gt;";
    echo $row['name'];
    $variants=$db-&gt;query("SELECT * FROM products where pid=$pid");
      foreach($variants as $r){
         if($pid==$r['id']){ //I checked this, condition is fine
           echo "&lt;input type='radio' checked&gt;".$r['name'];
         }
         else{
           echo "&lt;input type='radio'&gt;".$r['name'];
         }
      }
  }
  </code></pre>
  
  <p>Also when I click on other radio button, it shows its relevant div &amp; hides the other but again no radio button is checked.</p>
  
  <p>Any help will be appreciated.</p>