title: Radio Button inside Foreach Loop -PHP
body: <p>How can I retain the selected radio button checked inside a foreach loop? Im developing a web application that checks first whether the selected service is available or not.</p>
  
  <p>Here is my current code in foreach loop:</p>
  
  <pre><code>&lt;h4&gt;-- Touch Therapies --&lt;/h4&gt;
      &lt;?php
      $contents = get_service_touch(); //get_service_touch() = SELECT query to get touch therapies
      foreach($contents as $content) {
      ?&gt;
      &lt;input type="radio" name="content_id" value="&lt;?php echo $content['content_id']; ?&gt;"
      &lt;?php
      if(isset($_POST['content_id'])){
          echo 'checked = "checked"';
      }
      ?&gt;&gt; 
  
      &lt;?php echo nl2br($content['content']);?&gt;
      &lt;font color="red"&gt;&lt;b&gt;P&lt;?php echo nl2br($content['price']);?&gt;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;
      &lt;?php   
      } //endforeach;
      ?&gt;
  </code></pre>
  
  <p>However even if I select different service, when I click 'Check Availability' //(submit button) it always checks the last radio button.</p>
  
  <p>Picture of foreach output: <a href="http://oi61.tinypic.com/rrnujd.jpg" rel="nofollow">http://oi61.tinypic.com/rrnujd.jpg</a></p>