Home » Php » How to select option with array value

How to select option with array value

Posted by: admin June 30, 2018 Leave a comment

Questions:

Can someone explain me how to make a select option with the value’s of an array. I wrote some code myself but the field remains empty.

<select id="gebruiker" name="gebruiker" class="form-control">
   <?php
      $query = "SELECT * FROM users";
      $result = mysqli_query($conn, $query);

      while ($row1 = mysqli_fetch_array($result)):;
      ?>
           <option value="<?php
              echo $row1[0]; ?>">
              <?php
                 echo "<p>$row1[0] $row1[1]</p>"; ?>
           </option>
   <?php
      endwhile;
      ?>
</select>

The code needs to display the ID of the user ($row[0]) and the name ($row[1]).

Answers: