title: How to make selected value in form stay selected?
body: <p>In my database I got a table (<code>band</code>) with 2 columns (<code>band_id</code> and <code>title</code>). In PHP I got variable that stores selected id (<code>selected_band_id</code>) and a form that reads values from the table and displays form.</p>
  
  <p>Table:</p>
  
  <pre><code>+---------+---------+
  | band_id | title   |
  +---------+---------+
  |       1 | Title 1 |
  |       2 | Title 2 |
  |       3 | Title 3 |
  +---------+---------+
  </code></pre>
  
  <p>PHP:   </p>
  
  <pre><code>&lt;?php
    $query = "SELECT `band`.`band_id`, `band`.`title` FROM `band`";
    $result = mysqli_query($mysqli, $query);
    if (!$result) {
      die("Database query failed.");
    }
  ?&gt;
  
  &lt;?php
    if (isset($_POST['select_band'])) {
      $selected_band_id = $_POST['select_band'];
    }
  ?&gt;
  
  &lt;form method="post" name="form_band" action=""&gt;
    &lt;select name="select_band" onchange="javascript: submit()"&gt;
      &lt;?php
        while ($row = mysqli_fetch_assoc($result)) {
          echo "&lt;option value=".$row["band_id"] . "&gt;" .$row["title"] ."&lt;/option&gt;";
        }
      ?&gt;
   &lt;/select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How to make selected variable stay selected (shown) in a form? It always jumps to the first item in a list. I can't figure this out with PHP. Thanks for any suggestions!</p>