Echo “selected” inquiries and questions

otter588

New Member
I was following a tutorial on PHP and HTML on how to use option=selected, but I am confused. Here is my code: \[code\]<form name ="rating" method ="POST" action ="" /> <? echo "<input type = \"hidden\" name = accountID value = "http://stackoverflow.com/questions/13771930/. $row['accountID'] . ">";?><select name="rating"> <? $values = array('','Very Bad','Bad','Average','Above Average'); for ($i =0; $i < count($values); $i = $i + 1){ echo "<option value = http://stackoverflow.com/"$i\"" . if ($rating == $i + 1) {echo "selected";} . "> $values[$i] </option>"; } ?> </select><input type ="Submit" name ="formSubmit" value ="http://stackoverflow.com/questions/13771930/Submit"></form> <?\[/code\]What I am trying to achieve is to have whatever option is stored in the database to be selected by default. What am I missing in the code?
 
Back
Top