php - Keep a value from a dropdown list after posting -



php - Keep a value from a dropdown list after posting -

i trying write 3-part drop downwards list selection menu. sec drop downwards list dependent on info first list , 3rd drop downwards dependent on info second. have tried using post this, each time form submitted blanks out info previous downwards box , if seek utilize session variable store data, reset when form submit.

here code:

//get list of course of study subjects database $subjects = mysqli_query($con,"select subject db.course;"); echo "<select name='getsubject' onchange='this.form.submit()'>"; echo '<option value="" style="display:none;" ></option>'; while ($row=mysqli_fetch_array($subjects) ) { echo "<option value='" . $row['subject'] . "' >". $row['subject'] ."</option>"; //creates drop downwards list of subjects } echo "</select> &nbsp;"; $selectedsubject = $_post['getsubject']; echo $selectedsubject; //get list of course of study titles database, based on subject chosen $courses = mysqli_query($con,"select title db.course subject = '$selectedsubject';"); echo "<select name = 'gettitle' style='width:500px;' onchange='this.form.submit()'>"; echo '<option value="" style="display:none;"></option>'; while ($row=mysqli_fetch_array($courses) ) { echo "<option value='" . $row['title'] . "' >". $row['title'] ."</option>"; //creates drop downwards list of course of study titles } echo "</select> &nbsp;"; $selectedtitle = $_post['gettitle']; echo "$selectedtitle"; //get list of section numbers database, based on course of study chosen $sections = mysqli_query($con,"select section db.course title = '$selectedtitle';"); echo "<select name = 'getsection' style='width:200px;' onchange='this.form.submit()'>"; echo '<option value="" style="display:none;"></option>'; while ($row=mysqli_fetch_array($sections) ) { echo "<option value='" . $row['section'] . "' >". $row['section'] ."</option>"; //creates drop downwards list of course of study sections } echo "</select>"; $selectedsection = $_post['getsection']; $course = mysqli_query($con,"select title, subject, section db.course subject = '$selectedsubject';"); ?>

how can maintain info getsubject intact after selection gettitle , getsection made? after final drop downwards box selected print 3 selections below menu.i have been struggling several hours , not sure how much more abuse keyboard can take.

thanks in advance help.

add condition, within loop print options, uses selected argument if alternative selected on submit.

while ($row=mysqli_fetch_array($subjects)) { if($_post['getsubject'] == $row['subject']) $s = " selected"; else $s = ""; echo "<option value='{$row['subject']}'$s>{$row['subject']}</option>"; } while ($row=mysqli_fetch_array($courses)) { if($_post['gettitle'] == $row['title']) $s = " selected"; else $s = ""; echo "<option value='{$row['title']}'$s>{$row['title']}</option>"; } while ($row=mysqli_fetch_array($sections)) { if($_post['getsection'] == $row['section']) $s = " selected"; else $s = ""; echo "<option value='{$row['section']}'$s>{$row['section']}</option>"; }

hope helps.

php session post drop-down-menu

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -