Jump to content

[SOLVED] pre-populate SELECT <option>


odisey

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.