Forum Moderators: coopster
However if the current month is november the drop-down should not contain options such as october or september. How do I do this?
Also is there a better way to handle this issue? Please advise me as I dont know the best way to go about this matter.
Regards
Swati
column definitions and formats
[dev.mysql.com...]
the dates can also just be stored as strings which works fairly well. I try to store either YYYY-MM-DD, YYYY-MM-DD HH:MM:SS (if I need time) or just use unix timestamps which makes comparison and formatting as starightforward as possible.
if you were using unix timestamps, functions such as
$selectyear = strftime [php.net](%b-%Y,$timestamp);
would change the format of your saved value into the format you are using
>> if the current month is november the drop-down should not contain options such as october or september
what should it contain then?
thing is there are 2 portions to your question, you first need to decide what format will make it easiest for you to do all of the math/display you will need to do on your dates. Once you have figured that out it is simple to choose the best format to store it in.
Once you have decided on functionality and format you can then decide how the value needs to be formatted in your drop down and what functions to use to convert back end dates for math into displayable versions.
Start with the db date format decision then worry about how you are going to display it.
I figure for your dropdown
use date() [php.net] to get the current month and year
Build your drop down based on those values
insert it in any format you want
<form name="monthtest">
<select name="month">
<?
$today = time();
for ($i=1;$i<=6;$i++) {?><?
$today = strtotime("+1 month",$today);
$nextmonth = strftime("%b-%y",$today);
echo "<option value=\"$nextmonth\"";
echo ">" . $nextmonth . "</option>";
}
?>
</select>
</form>