odisey Posted November 18, 2007 Share Posted November 18, 2007 Hello, I am trying to do something that seems simple enough. I have a drop down menu on a record insert page. This is it: <select name="question5"> <option value="n~n~n">----SELECT----</option> <option value="5~0~1">Not Applicable</option> <option value="5~0~2">Unsatisfactory</option> <option value="5~1~3">Basic</option> <option value="5~3~4">Proficient</option> <option value="5~4~5">Distinguished</option> </select> I want to create an edit page, and I would like the edit page to first $query the db and get the already entered scores, then automatically set the current option on the drop down for the editor. For example if student 7001234 got a score of 3 on question 5, when the edit page loaded for that student_id number question 5 on the form would already be selected as "3". The options values are 5=question number~0-4=score~1-5=description of score (basic, proficient, etc.). I was thinking of setting the option based on an IF statement something such as: If $result (for a query of question 5 = 5 [this is distinguished]) { set option to ,,,,, } else (4) { set to } else (3) etc..... Does this make sense? How can I accomplish this? Marc Quote Link to comment https://forums.phpfreaks.com/topic/77831-solved-pre-populate-select/ Share on other sites More sharing options...
teng84 Posted November 18, 2007 Share Posted November 18, 2007 <? echo '<select name="question5">'; echo '<option value="n~n~n">----SELECT----</option>'; while($row=mysql_fetch_assoc($query)){ if ($item = 'yourvalue'){ $selected = 'selected'; }else{ $selected = ''; } echo '<option value="'.$row["yourfield"].'" '.$selected.'>$row["yourfield"]</option>' } echo '</select> '; ?> this is more of php i guess Quote Link to comment https://forums.phpfreaks.com/topic/77831-solved-pre-populate-select/#findComment-394134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.