Forum Moderators: coopster
<select name=\"month\" >
<option value=\"1\">January</option>
<option value=\"2\">February</option>
<option value=\"3\">March</option>
<option value=\"4\">April</option>
<option value=\"5\">May</option>
<option value=\"6\">June</option>
<option value=\"7\">July</option>
<option value=\"8\">August</option>
<option value=\"9\">September</option>
<option value=\"10\">October</option>
<option value=\"11\">November</option>
<option value=\"12\">December</option>
</select>
as you can see date is stored as an integer when this is sent to the DB. But i then need to read this value again! So i use..
//store DB value as an option
$data_month .=<<<HTML
<option value="$month">$month</option>
<option>------</option>
HTML;
//display drop down box with DB value
<select name=\"month\" >
$data_month
<option value=\"1\">January</option>
<option value=\"2\">February</option>
<option value=\"3\">March</option>
<option value=\"4\">April</option>
<option value=\"5\">May</option>
<option value=\"6\">June</option>
<option value=\"7\">July</option>
<option value=\"8\">August</option>
<option value=\"9\">September</option>
<option value=\"10\">October</option>
<option value=\"11\">November</option>
<option value=\"12\">December</option>
</select>
The problem is that I need $data_month to be shown as a Name (eg August) and not and integer. Other than use 12 'If' statements, is there an easy way of doing this?
Thankyou
$months = array(
"01" => "January",
"02" => "February",
"03" => "March",
"04" => "April",
"05" => "May",
"06" => "June",
"07" => "July",
"08" => "August",
"09" => "September",
"10" => "October",
"11" => "November",
"12" => "December"
);
You could pop this in an include file called 'months.php'. Then on the page you want to display your array, you could use:
@include('months.php');<select name="month" >
<?phpforeach ($months as $key => $value)
{
echo "<option value='$key'>$value</option>\n";
}?>
</select>
Hope that helps.
dc