I'm in the process of recoding some apps into PHP.
At one point I am loading a list box. I test the value being loaded, if it is a match with the value from the table record I add the "selected" to the option.
This should make that item appear in the drop down list.
When I examine the output in the browser I can see that the PHP code executed properly and added the "selected" attribute to the proper item in the list. However, the first item and NOT the selected item is displayed.
Perhaps this is a question for the HTML forum, however in my existing code in the other language which streams out this same page, the list box displays properly, so I'm thinking I have a PHP issue. Any suggestion is appreciated.
Here are 3 examples of what I have tried none work.
At one point I am loading a list box. I test the value being loaded, if it is a match with the value from the table record I add the "selected" to the option.
This should make that item appear in the drop down list.
When I examine the output in the browser I can see that the PHP code executed properly and added the "selected" attribute to the proper item in the list. However, the first item and NOT the selected item is displayed.
Perhaps this is a question for the HTML forum, however in my existing code in the other language which streams out this same page, the list box displays properly, so I'm thinking I have a PHP issue. Any suggestion is appreciated.
Here are 3 examples of what I have tried none work.
Code:
<select name="DATE_MONTH">
<?php
for ($n=0; $n<12; n++){
$m = $n+1;
if ($m == $this->cMonth)
{
?>
<option value="<?php echo $m;?>" SELECTED><?php echo $this->monthName[$n];?></option>
<?php
}else{
?>
<option value="<?php echo $m;?>"><?php echo $this->monthName[$n];?></option>
<?php
}
}
?>
</select>
<select name="DATE_DAY">
<?php
for ($n=1; $n<32; $n++){
if ($n == $this->cDay)
{
echo '<option value="'.$n.'" selected >'.$n.'</option>';
}else{
echo '<option value="'.$n.'">'.$n.'</option>';
}
}
?>
</select>
<select name="DATE_YEAR">
<option value="<?php echo $this->pYear;?>"><?php echo $this->pYear;?></option>
<option value="<?php echo $this->cYear;?>" selected><?php echo $this->cYear;?></option>
<option value="<?php echo $this->nYear;?>"><?php echo $this->nYear;?></option>
</select>
Comment