title: Using database output in HTML Select Tag with PHP
body: <p>I have the following working perfectly on a wordpress site.</p>
  
  <pre><code>&lt;?php 
  
  global $wpdb;
  
  $results = $wpdb-&gt;get_results( "SELECT post_title FROM wp_posts WHERE post_type = 'show' AND post_status = 'publish' ORDER BY post_title ASC" );
  $options = array();
  foreach ($results as $result) {
  $options[$result-&gt;post_title] =  $result-&gt;post_title;
  }
  
  echo '&lt;select class="field" name="djshow"&gt;';
  foreach ($options as $key =&gt; $value) {
  echo "&lt;option value='$key'" . ( $_GET['show'] == $value ? " selected='selected'" : "" ) . "&gt;$value&lt;/option&gt;";
  }
  '&lt;/select&gt;';
  
  ?&gt;
  </code></pre>
  
  <p>It searches the database for every instance of <em>post_title</em> from <em>wp_posts</em> where the <em>post_type</em> is <strong>show</strong> and the <em>post_status</em> is <strong>public</strong>. It then sorts it and outputs it to the array before populating a Select tag with a list of every <em>post_title</em> that matches.</p>
  
  <p>At the moment it outputs the <em>post_title</em> to both the option value and name fields....</p>
  
  <p>What I would like to do is select another field <em>ID</em> in the original query to populate the option value while the <em>post_title</em> populates the name.</p>
  
  <p>So the select would read something like this when rendered in html :</p>
  
  <pre><code>&lt;option value="15"&gt;Post Title 1&lt;/option&gt;
  &lt;option value="18"&gt;Post Title 2&lt;/option&gt;
  &lt;option value="23"&gt;Post Title 3&lt;/option&gt;
  etc...
  </code></pre>
  
  <p>I think the correct query I need to use is this (but correct me if i'm wrong)</p>
  
  <pre><code>$results = $wpdb-&gt;get_results( "SELECT post_title,ID FROM wp_posts WHERE post_type = 'show' AND post_status = 'publish' ORDER BY post_title ASC" );
  </code></pre>
  
  <p>But that's where my limited knowledge let's me down...</p>
  
  <p>How would I assign the output of <em>ID</em> to the option value and <em>post_title</em> to the name of the select tag?</p>