I instereted data into a database, one of the input fields is a "select". so the data is inserted and everything is ok there. now I made that you can edit the content. the problem now there is that if you edit the content the "select" is not showing the correct data. let's assume I selected value number 3 when I inserted the data, when I edit the data the drop down list shows not the correct one (it shows number 1) how can I make sure that the select shows the right thing? if it doesn't and the user saves the edited data the "select" data would change...
generate that 'select' code through php and put 'selected' where it should be 🙂
hope that helps
i tried this, but doesn't work:
echo '<tr> <td width="10"> </td> <select name="catg" selected="$catg"> <option value="one">one <option value="two">two </select> <span class="text2"></span></td></tr>';
"selected" goes on the option which you want to be selected like so:
<select name="catg"> <? $values = array("one", "two"); for($i=0;$i<count($values);$i++){ echo "<option value=\"".$values[$i]."\""; if(values[$i]==$catg){ echo " selected"; } echo ">".$values[$i]."</option>"; ?> </select>
hth, Kelvin.
thanks a lot BUt I coulnd't make the "for" working, so that it actually inserts all the possible values that could appear in the select are shown. what can I do?
Did you notice the typo?
if($values[$i]==$catg){ echo " selected"; }
And of course, you only want to do this if $catg actually has a value (which it won't first time out), so
if(isset($catg) && $values[$i]==$catg){ echo " selected"; }