title: How to get option list from database and select it?
body: <p>I want a dynamic option list which reads from database table lets say table of : Students,</p>
  
  <p>It must show to user the list of <code>student_name</code> and when it is selected by user it must send <code>student_id</code> of that student to the database. For example:</p>
  
  <pre><code>Students table :
  
  student_id             student_name 
  ----------------------------
  1                     John
  2                      Edward
  </code></pre>
  
  <p>In users option list must be included only John, Edward.. but when user selects John, the option picker must send only student_id('1') to database.</p>
  
  <p>My current code , but is not fetching list from db :S :
  yes, this is my code but for some reasons it ain't work :</p>
  
  <pre><code>&lt;select  Name='student_id'&gt;
              &lt;option value=""&gt;--- Select ---&lt;/option&gt;
              &lt;?
                  mysql_connect ("localhost","root","");
                  mysql_select_db ("mydb");
                  $select="student_name";
                  if (isset ($select)&amp;&amp;$select!=""){
                  $select=$_POST ['student_name'];
              }
              ?&gt;
              &lt;?
                  $list=mysql_query("select * from students order by student_name asc");
              while($row_list=mysql_fetch_assoc($list)){
                  ?&gt;
                      &lt;option value="&lt;? echo $row_list['student_id']; ?&gt;"&lt;? if($row_list['student_name']==$select){ echo "selected!"; } ?&gt;&gt;
                                           &lt;?echo $row_list['student_name'];?&gt;
                      &lt;/option&gt;
                  &lt;?
                  }
                  ?&gt;
              &lt;/select&gt;
  </code></pre>