How do I retain form values upon submit for a <select> loop?
<p>How do I retain form values upon submit for a  loop?</p>

<p>I've got something like this:</p>

<pre><code>&lt;?php
    printf ("&lt;optgroup label=\"CATEGORIES\"&gt;");

    foreach ($category as $key =&gt; $val) {
    printf ("&lt;option value=\"$key\"&gt;$val&lt;/option&gt;");
    }
    printf ("&lt;/optgroup&gt;");
?&gt;
</code></pre>

<p>When hitting submit on another part of my form, it resets the values in the select to the top one. I want it to keep the same value. How? For things like input boxes I have this that works: </p>

<pre><code>&lt;option value="5" name="results" &lt;?php if($_GET["results"] == '5'){  ?&gt; selected="selected" &lt;?php } ?&gt; &gt;5&lt;/option&gt;
</code></pre>

<p>This works because I'm not dynamically populating the dropdown from a database, so I don't need a loop to loop through values and populate the select.</p>
