title: How to set the default selected radio button in a group depending on a database value?
body: <p>html:</p>
  
  <pre><code>&lt;label&gt;&lt;input type="radio" name="league" value="Bronze"&gt;Bronze&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Silver"&gt;Silver&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Gold"&gt;Gold&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Platinum"&gt;Platinum&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Diamond"&gt;Diamond&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Master"&gt;Master&lt;/label&gt;
  &lt;label&gt;&lt;input type="radio" name="league" value="Grand Master"&gt;Grand Master&lt;/label&gt;
  </code></pre>
  
  <p>I have a database column that will save the one they select as a VARCHAR (should I be using something else?). How do I set it up so that the radio button that lines up with what is stored in the database will be selected?</p>
  
  <p>I may also just change this to a drop down menu, but I will still need to know how to set the selected value for that as well.</p>
  
  <p>Here is what I have tried, but it doesn't seem to work for some reason.</p>
  
  <pre><code>&lt;?php
       $leagues = array('Bronze', 'Silver', 'Gold', 'Platinum', 'Diamond', 'Master', 'Grand Master');
       foreach ($leagues as $key=&gt;$value) {
            $selected = ($value == $user_data['league'] ? ' selected="selected"' :  '');
            echo '&lt;label&gt;&lt;input type="radio" name="league"' . $selected . ' value="' . $value . '"&gt;' . $value . '&lt;/label&gt; ';
       }
  ?&gt;
  </code></pre>