473,499 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array results are not displayed incorrectly

6 New Member
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $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");
  3. $array_year = array("2005","2006","2007","2008","2009");
  4. $m_options = array();
  5. while (list($indx,$mth) = each ($array_month)) {
  6.     $tmp_mth->m_title = $mth;
  7.     $tmp_mth->m_value = "?month=".$indx."&year=".$year;
  8.     if ($indx == $month) {
  9.         $tmp_mth->selected = "selected";
  10.     }
  11.     array_push($m_options,$tmp_mth);
  12.     $tmp_mth->selected = "";
  13. }
  14. $y_options = array();
  15. foreach ($array_year as $yr) {
  16.     $tmp_yr->y_title = $yr;
  17.     $tmp_yr->y_value = "?month=".$month."&year=".$yr;
  18.     if ($yr == $year) {
  19.         $tmp_yr->selected = "selected";
  20.     }
  21.     array_push($y_options,$tmp_yr);
  22.     $tmp_yr->selected = "";
  23. print_r ($tmp_yr->y_title);
  24. print_r ($y_options);
  25. }
  26.  
  27.  
The url is http://ritc.view2offer.com.sg/course_calendar.php

I am not sure where is the possible problem. Would appreciate if anybody can help.
Sep 7 '07 #1
3 1082
Purple
404 Recognized Expert Contributor
Hi,

I have run your script with the following output:

Expand|Select|Wrap|Line Numbers
  1. y_options for year 2005
  2. Array ( [0] => stdClass Object ( [y_title] => 2005 [y_value] => ?month=August&year=2005 [selected] => ) ) 
  3. y_options for year 2006
  4. Array ( [0] => stdClass Object ( [y_title] => 2006 [y_value] => ?month=August&year=2006 [selected] => ) [1] => stdClass Object ( [y_title] => 2006 [y_value] => ?month=August&year=2006 [selected] => ) ) 
  5. y_options for year 2007
  6. Array ( [0] => stdClass Object ( [y_title] => 2007 [y_value] => ?month=August&year=2007 [selected] => ) [1] => stdClass Object ( [y_title] => 2007 [y_value] => ?month=August&year=2007 [selected] => ) [2] => stdClass Object ( [y_title] => 2007 [y_value] => ?month=August&year=2007 [selected] => ) ) 
  7. y_options for year 2008
  8. Array ( [0] => stdClass Object ( [y_title] => 2008 [y_value] => ?month=August&year=2008 [selected] => ) [1] => stdClass Object ( [y_title] => 2008 [y_value] => ?month=August&year=2008 [selected] => ) [2] => stdClass Object ( [y_title] => 2008 [y_value] => ?month=August&year=2008 [selected] => ) [3] => stdClass Object ( [y_title] => 2008 [y_value] => ?month=August&year=2008 [selected] => ) ) 
  9. y_options for year 2009
  10. Array ( [0] => stdClass Object ( [y_title] => 2009 [y_value] => ?month=August&year=2009 [selected] => ) [1] => stdClass Object ( [y_title] => 2009 [y_value] => ?month=August&year=2009 [selected] => ) [2] => stdClass Object ( [y_title] => 2009 [y_value] => ?month=August&year=2009 [selected] => ) [3] => stdClass Object ( [y_title] => 2009 [y_value] => ?month=August&year=2009 [selected] => ) [4] => stdClass Object ( [y_title] => 2009 [y_value] => ?month=August&year=2009 [selected] => ) ) 
to make it run I set:

[PHP]$month = "August";
$year = "2006";

// with the output generated using :

echo "<br>y_options for year ".$yr."<br>";
print_r ($y_options);

[/PHP]

can you give more details on what the problem is ?

Regards Purple
Sep 7 '07 #2
grace01
6 New Member
Thanks for your reply. Can you click http://ritc.view2offer.com.sg/course_calendar.php?

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 - December, 2005 to 2009.

Regards
Huifen
Sep 13 '07 #3
Weisbartb
36 New Member
Hello,
Expand|Select|Wrap|Line Numbers
  1.  
  2. $array_month = 
  3. while (list($indx,$mth) = each ($array_month)) {
  4.     $tmp_mth->m_title = $mth;
  5.     $tmp_mth->m_value = "?month=".$indx."&year=".$year;
  6.     if ($indx == $month) {
  7.         $tmp_mth->selected = "selected";
  8.     }
  9.     array_push($m_options,$tmp_mth);
  10.     $tmp_mth->selected = "";
  11. }
  12. foreach ($array_year as $yr) {
  13.     $tmp_yr->y_title = $yr;
  14.     $tmp_yr->y_value = "?month=".$month."&year=".$yr;
  15.     if ($yr == $year) {
  16.         $tmp_yr->selected = "selected";
  17.     }
  18.     array_push($y_options,$tmp_yr);
  19.     $tmp_yr->selected = "";
  20. print_r ($tmp_yr->y_title);
  21. print_r ($y_options);
  22. }
  23.  
  24.  
Your over writing your variables in your code. use something like this

[php]
$tmp_mth->m_title[] = $mth;
[/php]
Instead. That will place them in an array for you that will auto increment.
Sep 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
7028
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! ...
0
2910
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
2
3517
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
3
1906
by: Harold A. Mackey | last post by:
I have a situation where a user must enter three int results into three textboxes, save that entry and enter another set. All sets have to be displayed in another box or grid, and when the collection...
2
2029
by: Amrit Kohli | last post by:
Hello. I have the following code, to do a simple operation by copying the elements of a vector of strings into an array of char pointers. However, when I run this code, the first element in the...
2
3561
by: Bryan | last post by:
Apologies if this is a noob question, but I've been struggling with this for quite a while... I'm trying to convert a byte array (encrypted authorization code) into a *screen-printable* string...
1
2246
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
0
1159
by: dudeja.rajat | last post by:
Hi, I've used CTYPES module to access a function from a dll. This function provides me the version of the dll. This information is accessible to me as an array of 4 long inetegers. information...
6
2218
by: lukasso | last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.