title: Fetch Date from mysql db into dropdown box in PHP
body: <p>I am developing user edit form where users can edit their info. I wants only that date come in combo box which was user add in table as Date of Birth. In following code I successfully pull Month into Combo box which user added in table.  </p>
  
  <p>IN FOLLOWING LINE I RUN SELECT QUERY TO FETCH DATA FROM DB INCLUDING YEAR, MONTH AND DAY:</p>
  
  <pre><code>&lt;?php
  $cnic_selected=$_POST['all_cnic'];
  
  if(isset($cnic_selected))
  {
  $query = mysql_query("SELECT refer_id, emp_name, emp_father, emp_cnic, YEAR(emp_dob) AS byear, MONTH(emp_dob) AS bmonth, DAY(emp_dob) AS bday FROM staff_users WHERE emp_cnic = '$cnic_selected'");
  
  $count = mysql_num_rows($query);
  
  while($row = mysql_fetch_object($query))
  {
  $ref = $row-&gt;refer_id;
  $name = $row-&gt;emp_name;
  $fname = $row-&gt;emp_father;
  $cnic = $row-&gt;emp_cnic;
  $byear = $row-&gt;byear;
  $bmonth = $row-&gt;bmonth;
  $bday = $row-&gt;bday;
      }
  
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;table width="95%"&gt;
  &lt;form name="edituserform" action="" method="Post" onSubmit="return validateform(this);"&gt;
  
  &lt;tr&gt;&lt;td width="125px"&gt;&lt;b&gt;Referral Code&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $ref; ?&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;Full Name&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="emp_name" id="emp_name" value="&lt;?php echo $name; ?&gt;" /&gt;
  &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;Father's Name&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="emp_father" id="emp_father" value="&lt;?php echo $fname; ?&gt;" /&gt;
  &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;CNIC Number&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $cnic; ?&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;b&gt;Date of Birth&lt;/b&gt;&lt;/td&gt;
  &lt;td&gt;
  
  /* Run Loop to generate 31 days of the month */
  &lt;select name="dt"&gt;
  &lt;option value='--'&gt;--&lt;/option&gt;
  &lt;?php 
  for ($d=1; $d&lt;32; $d++)
  {
  "&lt;option value='$d'&gt;$d&lt;/option&gt;";
   }
  ?&gt;
  &lt;/select&gt;
  
  /* Here I manually type months list. Use "Selected" to fetch that month which user select in DB */
  
  &lt;select name="month"&gt;
  &lt;option value="--"&gt;--&lt;/option&gt;
  &lt;option value='01' &lt;?php echo ($bmonth == 1) ? 'selected="selected"': ''; ?&gt;&gt;
  Jan&lt;/option&gt;
  &lt;option value='02' &lt;?php echo ($bmonth == 2) ? 'selected="selected"': ''; ?&gt;&gt;
  Feb&lt;/option&gt;
  &lt;option value='03' &lt;?php echo ($bmonth == 3) ? 'selected="selected"': ''; ?&gt;&gt;
  Mar&lt;/option&gt;
  &lt;option value='04' &lt;?php echo ($bmonth == 4) ? 'selected="selected"': ''; ?&gt;&gt;
  Apr&lt;/option&gt;
  &lt;option value='05' &lt;?php echo ($bmonth == 5) ? 'selected="selected"': ''; ?&gt;&gt;
  May&lt;/option&gt;
  &lt;option value='06' &lt;?php echo ($bmonth == 6) ? 'selected="selected"': ''; ?&gt;&gt;
  Jun&lt;/option&gt;
  &lt;option value='07' &lt;?php echo ($bmonth == 7) ? 'selected="selected"': ''; ?&gt;&gt;
  Jul&lt;/option&gt;
  &lt;option value='08' &lt;?php echo ($bmonth == 8) ? 'selected="selected"': ''; ?&gt;&gt;
  Aug&lt;/option&gt;
  &lt;option value='09' &lt;?php echo ($bmonth == 9) ? 'selected="selected"': ''; ?&gt;&gt;
  Sep&lt;/option&gt;
  &lt;option value='10' &lt;?php echo ($bmonth == 10) ? 'selected="selected"': ''; ?&gt;&gt;
  Oct&lt;/option&gt;
  &lt;option value='11' &lt;?php echo ($bmonth == 11) ? 'selected="selected"': ''; ?&gt;&gt;
  Nov&lt;/option&gt;
  &lt;option value='12' &lt;?php echo ($bmonth == 12) ? 'selected="selected"': ''; ?&gt;&gt;
  Dec&lt;/option&gt;
  &lt;/select&gt;
  
  
  &lt;select name="year"&gt;
  &lt;option value='--'&gt;--&lt;/option&gt;
  &lt;?php
  for ($y=2000; $y&gt;1950; $y--)
  { 
  echo "&lt;option value='$y'&gt;$y&lt;/option&gt;";
  }
  ?&gt;
  &lt;/select&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now my question is Please tell how to pull Year and Day from table into combo box which user was added while I am using Loop to generate years and days!??</p>
  
  <p>Regards,</p>
  
  <p>MAT</p>