title: Foreach php function HTML select
body: <p>I am trying to make a select dropdown with html and the value must be something from the database, 
  the select is in a php function and for some reason my foreach loop is not working correctly, when I click on the select, the values are empty, -> I am doing something wrong :) </p>
  
  <pre><code>    function getWork() {
  echo date ( 'l, F j, Y', strtotime ( 'friday + 1 weekdays' ) ) . "\n";
      echo '&lt;h1&gt;&lt;a href="dashboard.php"&gt;Het terras&lt;/a&gt; &amp;rsaquo; &lt;a href="dashboard.php?app=users"&gt;Roosters&lt;/a&gt; &amp;rsaquo; &lt;a href="dashboard.php?app=users&amp;action=new"&gt;setup&lt;/a&gt;&lt;/h1&gt;';
      echo'&lt;p&gt;Selecteer de persoon waarvan u de data wilt aanmaken&lt;/p&gt;'; 
      /*Foreach loop */ 
          $connection = mysqlConnect();
  
   // Find out how many items are in the table
      $total = $connection-&gt;query('SELECT COUNT(*) FROM intranet_users')-&gt;fetchColumn();
  
      // How many items to list per page
      $limit = 20;
  
      // How many pages will there be
      $pages = ceil($total / $limit);
  
      // What page are we currently on?
      $page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
          'options' =&gt; array(
              'default'   =&gt; 1,
              'min_range' =&gt; 1,
          ),
      )));
  
      // Calculate the offset for the query
      $offset = ($page - 1)  * $limit;
  
      // Some information to display to the user
      $start = $offset + 1;
      $end = min(($offset + $limit), $total);
  
      // The "back" link
      $prevlink = ($page &gt; 1) ? '&lt;a href="?app=users&amp;page=1" title="Eerste pagina"&gt;&amp;laquo;&lt;/a&gt; &lt;a href="?app=users&amp;page=' . ($page - 1) . '" title="Vorige pagina"&gt;&amp;lsaquo;&lt;/a&gt;' : '&lt;span class="disabled"&gt;&amp;laquo;&lt;/span&gt; &lt;span class="disabled"&gt;&amp;lsaquo;&lt;/span&gt;';
  
      // The "forward" link
      $nextlink = ($page &lt; $pages) ? '&lt;a href="?app=users&amp;page=' . ($page + 1) . '" title="Volgende pagina"&gt;&amp;rsaquo;&lt;/a&gt; &lt;a href="?app=users&amp;page=' . $pages . '" title="Laaste pagina"&gt;&amp;raquo;&lt;/a&gt;' : '&lt;span class="disabled"&gt;&amp;rsaquo;&lt;/span&gt; &lt;span class="disabled"&gt;&amp;raquo;&lt;/span&gt;';
  
      // Prepare the paged query
      $stmt = $connection-&gt;prepare('SELECT * FROM intranet_users');
  
      // Bind the query params
      $stmt-&gt;bindParam(':limit', $limit, PDO:: PARAM_INT);
      $stmt-&gt;bindParam(':offset', $offset, PDO:: PARAM_INT);
      $stmt-&gt;execute();
  
      // Do we have any results?
      if ($stmt-&gt;rowCount() &gt; 0) {
          // Define how we want to fetch the results
          $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC);
          $iterator = new IteratorIterator($stmt);
  
          // Display the results  
      echo '&lt;p&gt;&lt;form method="post" action="foreach2.php"&gt;';
      echo '&lt;select name="pty_select" &gt;';
          foreach ($iterator as $row){
              echo '&lt;option value="';
              echo $row['firstname'];
              echo '&lt;/option&gt;"';  
          } 
       echo '   &lt;/select&gt;&lt;/p&gt; '; 
      }   
      /*Einde loop */
      echo '
  &lt;input type="text" id="datepicker" name="datepicker" placeholder="Selecteer uw Datum"&gt; &lt;br/&gt;
  &lt;input type="text" id="tijd" name="#" placeholder="Selecteer uw begijn tijd"&gt; &lt;br/&gt;
  &lt;input type="submit" value="Save"&gt;
  &lt;/form&gt;';
  }
  </code></pre>
  
  <p>I think the problem is somewhere here:</p>
  
  <pre><code>// Display the results  
          echo '&lt;p&gt;&lt;form method="post" action="foreach2.php"&gt;';
          echo '&lt;select name="pty_select" &gt;';
              foreach ($iterator as $row){
                  echo '&lt;option value="';
                  echo $row['firstname'];
                  echo '&lt;/option&gt;"';  
              } 
           echo '   &lt;/select&gt;&lt;/p&gt; '; 
  </code></pre>
  
  <p>I know there are similiar questions, I've read <a href="https://stackoverflow.com/questions/16034281/foreach-php-function-inside-html-select-options">Foreach php function inside HTML select options</a> but still not working :(</p>