Array results are not displayed incorrectly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
grace01
Forum Newbie
Posts: 5
Joined: Wed Sep 05, 2007 3:43 am

Array results are not displayed incorrectly

Post by grace01 »

Hello,

My php program cannot display result correctly. After run array_push($y_options,$tmp_yr), $y_options doesn't show 2005, 2006, 2007, 2008, 2009. $y_options only show 2009, 2009, 2009, 2009, 2009.

Same for $m_options. It only show December rather than January to December.

My source code is as follow:

Code: Select all

$array_month = array("1"=>"January","2"=>"Febuary","3"=>"March","4"=>"April","5"=>"May","6"=>"June","7" =>"July","8"=>"August","9"=>"September","10"=>"October","11"=>"November","12"=>"December");
$array_year = array("2005","2006","2007","2008","2009");
$m_options = array();
while (list($indx,$mth) = each ($array_month)) {
    $tmp_mth->m_title = $mth;
    $tmp_mth->m_value = "?month=".$indx."&year=".$year;
    if ($indx == $month) {
        $tmp_mth->selected = "selected";
    }
    array_push($m_options,$tmp_mth);
    $tmp_mth->selected = "";
}
$y_options = array();
foreach ($array_year as $yr) {
    $tmp_yr->y_title = $yr;
    $tmp_yr->y_value = "?month=".$month."&year=".$yr;
    if ($yr == $year) {
        $tmp_yr->selected = "selected";
    }
    array_push($y_options,$tmp_yr);
    $tmp_yr->selected = "";
print_r ($tmp_yr->y_title);
print_r ($y_options);
}
you can click http://ritc.view2offer.com.sg/course_calendar.php to see the result of month and year.

When you click drop down menu Month and Year, it always show December and 2009. The correct result of drop down menu should be January to December, 2005 to 2009.

I am not sure where is the possible problem. Would appreciate if anybody can help.

Regards,
Grace
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Duplicate thread; locked. Original: viewtopic.php?t=73378
Locked