problem with drop down list..

A

Anonymous

Guest
hi guys...i've got a problem with the drop down list. some of the inputs that i asked from user is using the drop down list in the form. when i key in all the input, all the data save to the database successfully. but when i want to edit the input in the form after saving all in the database, i cant extract the value that user selected for the input in the drop down list. the value that will come out is the first value in the list. i dont know what i'm supposed to do about that. i guess maybe i should make an if statement or something like that...can anybody give me the explanation or sample codes????below i paste my codes:

********************************************************************************************************

<tr>
<td class="p5px left"> Working Shift </td>
<td class="p5px left"><select name="w2" selected = "<?php echo $shift;?>" >
<option value="shift">Morning </option>
<option value="shift">Afternoon </option>
<option value="shift">Night </option>
</select>
</td>
</tr>
 
Try this loop out:
Code:
<?php

// Let's say you've already fetched the DB and
// Your need field data (the one for this options) is in $row['opval'] ...

// Now here define all your html imputs' data

// If you need a value different from the option name, just set it in the following array
// E.g.: $options_array = array('M' => 'Morning','A' => 'Afternoon','N' => 'Night');
// So you can use $op_key and $op_val

$options_array = array('Morning','Afternoon','Night');

print '<select name="w2">' . "\n"; 
   foreach($options_array as $op_key => $op_val) {
        print '<option value="' . $op_val . '"' 
              . (($op_val == $row['opval']) ? 'selected="selected"' : '') . '>';
        print $op_val . '</option>' . "\n";
   }
print '</select>' . "\n";

?>
It should work!
 
tq for ur explanation..but i'm not sure where to put all those thing???can u explain it in more details plezzz!!!!
 
In the code you've posted :)
Code:
<tr> 
<td class="p5px left"> Working Shift </td> 
<td class="p5px left">
<?php

// Query your DB here and fetch the needed data
// Don't forget to change the variable used in the html options: $row['opval'].

$options_array = array('Morning','Afternoon','Night');

print '<select name="w2">' . "\n";    

foreach($options_array as $op_key => $op_val) {
     print '<option value="' . $op_val . '"' . (($op_val == $row['opval']) ? 'selected="selected"' : '') . '>';
     print $op_val . '</option>' . "\n";   
}

print '</select>' . "\n";

?>
</td> 
</tr>
That's all... go test it!
 
tq so much gesf... :D i really appreciate ur help..tq so muchhh
 
Back
Top