Jump to content

[SOLVED] pre-populate SELECT <option>


Recommended Posts

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 

Link to comment
https://forums.phpfreaks.com/topic/77831-solved-pre-populate-select/
Share on other sites

<?
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.