title: Is it possible to return the nth field of a table in MySQL?
body: <p>I'm trying to use PHP to populate drop-down menus with data from certain columns of separate tables. But, I have many menus to populate, so instead of making a function specific to each, I wanted to pass the column name (which is the field, right?) to the function.</p>
  
  <p>Currently I have this for one menu</p>
  
  <pre><code>function print_dropdown($query, $link){
     $queried = mysql_query($query, $link);
     $menu = '&lt;select name="wholesaler" id="wholesaler"&gt;';
     while ($result = mysql_fetch_array($queried)) {
         $menu .= '&lt;option value="' . $result['id'] . '"&gt;' . $result['wholesaler'] . '&lt;/option&gt;';
     }
     $menu .= '&lt;/select&gt;';
     return $menu;
  }
  ...
  &lt;?php echo print_dropdown("SELECT id, wholesaler FROM wholesaler_flag LIMIT 0, 10", $connect_normas_boudoir);
  ?&gt;
  </code></pre>
  
  <p>But, I'd like to do this:</p>
  
  <pre><code>function get_field($table){
      $col_2 = mysql_query('SHOW COLUMNS FROM "$table" WHERE FIELD = 2');
      return $col_2;
  }
  
  function print_dropdown($query, $link){
      $queried = mysql_query($query, $link);
      $menu = '&lt;select name="'$col_2'" id="'$col_2'"&gt;';
      while ($result = mysql_fetch_array($queried)) {
          $menu .= '&lt;option value="' . $result['id'] . '"&gt;' . $result['$col_2'] . '&lt;/option&gt;';
      }
      $menu .= '&lt;/select&gt;';
      return $menu;
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>&lt;?php
      get_field(wholesaler_flag);
      echo print_dropdown("SELECT id, wholesaler FROM wholesaler_flag LIMIT 0, 10", $connect_normas_boudoir);
  ?&gt;
  </code></pre>
  
  <p>Is it bad form to try and select the second field of each table? In my case there are only two columns in each table concerned. But, I understand that in future a new column could, theoretically, be inserted after id. Is there a better way to do this? Please excuse if I've botched up my single and double quotes. Still learning.</p>
  
  <p><strong>Note:</strong> I've tried <code>SHOW COLUMNS FROM wholesaler_flag WHERE FIELD = 2;</code> in the MySQL console. Of course it didn't work, but I thought there might be a way of accessing that. This is the specific area with which my question is concerned.</p>