Q:

Php if function error

In below code...the tag is "$mname1" is right now, taking only three value APRIL, MAY, JUNE.
if ( $profile_stats['month'] < $old_month && $profile_stats['year'] == $old_year
                    || $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) {
                    ?>

<?php
                    }
                    else {

                        if ( $profile_stats['month'] == 1      ) {
                        $mname1 = 'January';
                        }
                        elseif ( $profile_stats['month'] == 2 ) {
                        $mname1 = 'Feburary';
                        }
                        elseif ( $profile_stats['month'] == 3 ) {
                        $mname1 = 'March';
                        }
                        elseif ( $profile_stats['month'] == 4 ) {
                        $mname1 = 'April';
                        }
                        elseif ( $profile_stats['month'] == 5 ) {
                        $mname1 = 'May';
                        }
                        elseif ( $profile_stats['month'] == 6 ) {
                        $mname1 = 'June';
                        }
                        elseif ( $profile_stats['month'] == 7 ) {
                        $mname1 = 'July';
                        }
                        elseif ( $profile_stats['month'] == 8 ) {
                        $mname1 = 'August';
                        }
                        elseif ( $profile_stats['month'] == 9 ) {
                        $mname1 = 'September';
                        }
                        elseif ( $profile_stats['month'] == 10 ) {
                        $mname1 = 'October';
                        }
                        elseif ( $profile_stats['month'] == 11 ) {
                        $mname1 = 'November';
                        }
                        elseif ( $profile_stats['month'] == 12 ) {
                        $mname1 = 'December';
                        }

                        if ( $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) {
                        $mname1 = "<i>Current Month</i> - $mname1";
                        }

                        if ( $profile_stats['month'] == 04 && $profile_stats['year'] == 2012 ) {
                        $newstats_alert = "<p><b style='color: red;'><i>April 2012 stats are only partial due to implementation of this feature mid month.</i></b></p>";    

                        }
                        else {
                        $newstats_alert = NULL;
                        }

                    ?>

Here,      
  date("m") shows value 10 10 10
  date("Y") shows 12 12 12
  $profile_stats['month'] shows 05 04 03
  $profile_stats['year'] shows 2012 2012 2012
  $old_month shows 10 10 10
  $old_year shows 2011 2011 2011

I am printing a table using all this..below is the code:
<tr>
        <td colspan='4' style='border: 2px solid black;'><div align="center"><b><u><?=$mname1?> <?=$profile_stats['year']?></u></b><?=$newstats_alert?></div></td>
 </tr>
 <tr>
<td>Profile Views</td>
<td>Course Views</td>
<td>General Enquiries</td>
<td>Course Enquiries</td>
 </tr>
 <tr>
<td><?=($profile_stats['profile_views'] + 0)?></td>
<td><?=($course_views[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>
<td><?=($profile_stats['general_enquiries'] + 0)?></td>
<td><?=($course_enquiries[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>
</tr>

<tr>
<td colspan='2'>Total Views: <?=($profile_stats['profile_views'] + $course_views[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>
<td colspan='2'>Total Enquiries: <?=($profile_stats['general_enquiries'] + $course_enquiries[$profile_stats['year']."-".$profile_stats['month']] + 0)?></td>
 </tr>

This code is generating table for April, May and June only...What I want to ask you that is there any way to edit this code to print the table upto date("m")-1 month i.e. till september.
Please Help me

A:

First, you can get rid of all the if-elseif by doing this:
$months = array("January","February", "March",... );
$mname1 = $months[$profile_stats['month']-1];

Second, regarding your question - now it's easy to go over $months in a for-loop - until the "last month":
for($i=0; $i<$profile_stats['month']-1; $i++){
   echo $mname1[$i];
}

