Drop down menu and retaining value after submit

Hello,

Kindly check this code. It is working however it seems very long. I was hoping if this can be optimize. I also wish to remove the ctr variable so I can add many value in array without counting them.

[php]Shift
- Select -
<?php
$ctr2=0;
$time1=array (“1st Shift”,“2nd Shift”,“3rd Shift”);
while($ctr2<=2) {
if($time1[$ctr2] == $_POST[‘ftime’]) {
echo “$time1[$ctr2]\n\t\t\t”;
} else {
echo “$time1[$ctr2]\n\t\t\t”;
}
$ctr2++;
}
?>

[/php]

I read on some website that foreach command can be use.
Is that possible here?

Thanks in advance.

You could do it like this:

[php]
Shift
- Select -
<?php
$time1 = array(“1st Shift”,“2nd Shift”,“3rd Shift”);
for ($intCount = 0; $intCount <= count($time1); $intCount++){
if($time1[$intCount] == $_POST[‘ftime’]) {
echo “$time1[$intCount]\n\t\t\t”;
} else {
echo “$time1[$intCount]\n\t\t\t”;
}
}
?>

[/php]

Hello xerxes,

Thanks so much for the code. Somehow I manage to make t work. However the is a blank at the last selection but I manage to removed it by using this code below. I removed the ‘=’. Now it is working ok. thanks a lot.

[php]$intCount < count($time1);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service