title: Foreach php function inside HTML select options
body: <p>Im a newbie to this forum and have just started coding in php. Need some help. I have the following code</p>
  
  <pre><code>&lt;?php error_reporting(-1);
  
  require_once('/mysql/sql_connect.php');
  
  $q = "SELECT pty.pty_profile_name AS profile FROM pty, users WHERE users.username = 'testaccount' ";
      $r = @mysqli_query ($dbc, $q);
  
      $results_array = array();
      while($row = mysqli_fetch_assoc($r)) {
          array_push($results_array, $row);
      echo "&lt;pre&gt;"; print_r($results_array); echo "&lt;/pre&gt;"; }
  
  ?&gt;
  
  &lt;p&gt;
  &lt;form method="post" action="foreach2.php"&gt;
  &lt;label for="Property Select" class="title"&gt;Select Property&lt;/label&gt;  
     &lt;select name="pty_select" &gt; 
     &lt;?php foreach($results_array as $key =&gt; $value){ ?&gt;
                      &lt;option value="&lt;?php echo $key; ?&gt;"&gt;&lt;?php echo $value['profile']; ?&gt;&lt;/option&gt; 
      &lt;?php } ?&gt;
          &lt;/select&gt;
      &lt;input type="submit" name="Submit" /&gt;
  &lt;/form&gt;
  
  &lt;?php 
  
  if (isset($_POST['Submit'])) {
  echo "&lt;pre&gt;"; echo ($_POST['pty_select']); echo "&lt;/pre&gt;"; } ?&gt; 
  </code></pre>
  
  <p>The output I get is correct, but it displays the key, eg, 0 or 1 or 2, based on what I select in the form. I need the value output. Eg <code>0 = Emerton</code>, it outputs "0" instead of <code>Emerton</code>.</p>
  
  <p>If I echo <code>$value['profile']</code> instead of <code>pty_select</code>, I get the last result of the query all the time. Which in this example would be 2, which is <code>Ambarvale</code> as I believe it just chooses the last row output of the query.</p>
  
  <p>I hope I've made sense. Thanks in advance.</p>