jquery - Set default option in php dropdown and retain when submitted query -


i have below code creates drop-down php. want achieve 2 things here. 1. want set 1 of option set default. may hard coded or selected query. 2. when hit button, should retain selected option. retrieve selected option using session data this: echo $print_version1[array_keys($print_version1)[0]];

drop-down code:

$result = $conn->query("select distinct nx_version workflow1 order id desc"); echo "<form action='http://localhost/w_5aug/process.php' method='get'>"; echo "<html>"; echo "<body>"; echo "<p></p>"; echo "<center>"; echo "<strong> select base verison compare : </strong>"; echo "<select name='nx_version' id='nx_version'>";       while ($row = $result->fetch_assoc()) {              $nx_version = $row['nx_version'];               echo '<option>'.$nx_version.'</option>'; } echo "</select>"; echo "&nbsp;<button type='submit'><b>add base verison</b></button>";     echo "</center>"; echo "</body>"; echo "</html>"; echo "<p></p>";   $array_select = $_session['data']; print_r($array_select); echo "<form>"; 

i assume option should selected is$print_version1[array_keys($print_version1)[0]

while ($row = $result->fetch_assoc()) {          $nx_version = $row['nx_version'];            if($_session["id"])  {            if($nx_version == "the hardcode value want selected"){               echo '<option selected="selected">'.$nx_version.'</option>';            }else{               echo '<option>'.$nx_version.'</option>';            }          }else{            if($print_version1[array_keys($print_version1)[0]] == $nx_version){              echo '<option selected="selected">'.$nx_version.'</option>';            }else{              echo '<option>'.$nx_version.'</option>';            }         }   } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -