Forum Moderators: coopster
I am trying to build a select in php, it must make current month "selected" AND this is where I am stuck, should only generate the current month and the remainder of the current years months, heres what I have so far.
$montharray = array('Jan' => 'January','Feb' => 'February', 'Mar' => 'March', 'Apr' => 'April',
'May' => 'May', 'Jun' => 'June', 'Jul' => 'July', 'Aug' => 'August', 'Sep' => 'September',
'Oct' => 'October', 'Nov' => 'November', 'Dec' => 'December');
$currentmonth = date("M");
print "<select name=\"month\" size=\"1\">";
foreach ( $montharray as $key=>$val )
if ($key == $currentmonth)
{
print"<option value=\"$key\" selected>$val</option> \n";
}
else
{
print"<option value=\"$key\">$val</option> \n";
}
print "</select>";
How can I tell it to only create current and following months?
Thanks
$montharray = array(
1 => 'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);
$monthNumber = date('n');
print "<select name=\"month\" size=\"1\">";
for ($m = $monthNumber; $m <= 12; $m++) {
$monthAbbreviation = substr($montharray[$m], 0 , 3);
if ($m == $monthNumber) {
print"<option value=\"$monthAbbreviation\" selected>$montharray[$m]</option> \n";
} else {
print"<option value=\"$monthAbbreviation\">$montharray[$m]</option> \n";
}
}
print "</select>";
I had already changed to 01=>January etc then on the result spage did a case switch to convert it back to jan etc, your method takes further load of the server.
thank you
I have another select in the form,which I have just started working on, its a multiple select, it grabs a bunch of pre formatted dates from a database, I also want to tell that to only list dates from now until the end of the year, the dates in the db are like this Jan 12/13/14, which is Fri/Sat/Sun, its the same dates I was searching with the original select.
What method would work for that, to show it I am using
$sql="select * from dates";
$result = mysql_query($sql, $dblink) or die("System down");
while ($newArray = mysql_fetch_array($result)){
$val = $newArray['dates'];
print "<option value=\"$val\">$val</option>";
}
which displays them fine, now I need to only show current and following months of the year, I just need to know WHAT method to use, like you pointed out one based array and the method you would use, what would you do for this one?
Thanks again