I already have a select option like this:
<?php
echo 'Age : <select id="age" name ="age" class="selecta">';
for($i = 0; $i <= 24; $i += 0.25)
{
?>
<option value="<?php echo $i ;?>"
<?php
if ($_SESSION['age'] == $i)
{
echo " selected='selected'";
}
?> >
<?php echo $i .'  ' ?>
</option>
<?php
}
echo '</select> months <br />';
?>
which works good and displays this :
0 // means 0 month
0.25 // means 1 week or 0.25 of month
0.50 // means 2 weeks or half month
0.75
1 // means 1 month
1.25
....
24
but it doesn’t look too good for users. So what I want is to have them like this:
0 // 0month
1 week
2 weeks
3 weeks
4 weeks
1 month
1 month and 1 week
1 month and 2 weeks
.....
24 months
It’s not my final desire to be exactly like that but I would something like that.
Is this possible?
You are having a sequence of 97 iterations here. It is equally to
You then map any of these step to a specific number:
Which would for example create the following sequence:
So now you don’t want these numbers but just the nice months. You can just calculate them if you take the steps (instead your fractional numbers) more easily:
Or as the mapping function to turn that into text:
For example:
So now you only need to map the range as keys to their values and then you can do the standard output of a select box with these values:
Which gives you your output (Demo):