I am working on a website using a PHP script to display information formatted a certain way from a MySQL database. I want the date values from the database (which are formatted as YYYY-MM-DD) to be displayed as Month YYYY. The perhaps-not-efficient-enough code I'm using to display the months as words is below:
foreach($monthstart as $monthnext)
{
preg_match("/[[0-9][0-9]]*/", $monthnext, $startmonthfull);
}
echo "<b>Duration: </b>";
foreach($startmonthfull as $which)
{
if($which == 01)
{
echo "January ";
}
elseif($which == 02)
{
echo "February ";
}
elseif($which == 03)
{
echo "March ";
}
elseif($which == 04)
{
echo "April ";
}
elseif($which == 05)
{
echo "May ";
}
elseif($which == 06)
{
echo "June ";
}
elseif($which == 07)
{
echo "July ";
}
elseif($which == 08)
{
echo "August ";
}
elseif($which == 09)
{
echo "September ";
}
elseif($which == 10)
{
echo "October ";
}
elseif($which == 11)
{
echo "November ";
}
elseif($which == 12)
{
echo "December ";
}
}
foreach($year as $printyear)
{
echo $printyear;
}
This code displays the month and year for the first part. This displays perfectly on the webpage, unless the month is August or September. If the month is August or September, nothing gets printed for that part, so instead of "August 2005") you'd get "2005".
The August and September elseif statements are formatted (from what I can tell) exactly the same as the others so I have no idea why these values are not printing. If I simply ask it to print the $which value, it prints as either 08 or 09 and the values look proper in the database. I'm really hoping there is something simple I am overlooking that someone will quickly point out because I have been banging my head against the wall for quite some time with this issue.
(I'm not sure if it makes any difference, but I am using the Jumi plugin in Joomla which allows users to add custom code in a Joomla page to develop this section of the website.)
EDIT: I just removed the 0s from 08 and 09 and now they all display properly. So I guess now the question is why did this fix the problem when in the variable that is being checked the values are 08 and 09?
Also, sorry for solving it so shortly after posting a question.