title: How can I pre-select an option in a select menu based on a value stored in the database?
body: <p>I have a number of dropdown lists, which update a database, however once updated the first object on the list is displayed, rather than the actual object selected.  What is the best way to fix this?</p>
  
  <p>Code sample:
  HTML code sample</p>
  
  <pre><code>&lt;select name="sleeps"&gt;
         &lt;option value="0"&gt;Sleeps&lt;/option&gt;
         &lt;option value='1'&gt;1&lt;/option&gt;
         &lt;option value='2'&gt;2&lt;/option&gt;
         &lt;option value='3'&gt;3&lt;/option&gt;
         &lt;option value='4'&gt;4&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>This is generated using: </p>
  
  <pre><code> &lt;?php 
                                  for ($x = 1; $x &lt;=10; $x++) {
                                      echo "&lt;option value='$x'&gt;$x&lt;/option&gt;";
                                  }
  ?&gt;
  </code></pre>
  
  <p><strong>Desired result</strong></p>
  
  <pre><code> &lt;select name="sleeps"&gt;
         &lt;option value="0"&gt;Sleeps&lt;/option&gt;
         &lt;option value='1'&gt;1&lt;/option&gt;
         &lt;option value='2'&gt;2&lt;/option&gt;
         &lt;option value='3'&gt;3&lt;/option&gt;
         &lt;option value='4' selected&gt;4&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>