GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Sep-2006, 08:02
bouton bouton is offline
New Member
 
Join Date: Sep 2006
Posts: 2
bouton is on a distinguished road
Post

getting associative array to output correct including missing value


I have an associative array that looks like
Code:
Array ( [0] => Array ( [graph_user_hpcx_last_name] => Smith [graph_user_hpcx_Accounting_Year] => 2006 [graph_user_hpcx_Accounting_Month] => 6 [graph_user_hpcx_AllocationUnits] => 104 ) [1] => Array ( [graph_user_hpcx_last_name] => Brown [graph_user_hpcx_Accounting_Year] => 2006 [graph_user_hpcx_Accounting_Month] => 6 [graph_user_hpcx_AllocationUnits] => 316 ) [2] => Array ( [graph_user_hpcx_last_name] => Smith [graph_user_hpcx_Accounting_Year] => 2006 [graph_user_hpcx_Accounting_Month] => 7 [graph_user_hpcx_AllocationUnits] => 310 ) [3] => Array ( [graph_user_hpcx_last_name] => Doe [graph_user_hpcx_Accounting_Year] => 2006 [graph_user_hpcx_Accounting_Month] => 7 [graph_user_hpcx_AllocationUnits] => 36 )

What I'm trying to do is come up with a loop (to use in a graphing program XML-SWF Charts) which will produce a table like
June July
Smith 104 310
Brown 316 0
Doe 0 36

which is a listing like

begin graph_user_hpcx_last_name:
Smith
Brown
Doe
end graph_user_hpcx_last_name:

begin graph_user_hpcx_Accounting_Month = 6
June
104
316
0
end_graph_user_hpcx_Accounting_Month = 6

begin graph_user_hpcx_Accounting_Month = 7
July
310
0
36
end_graph_user_hpcx_Accounting_Month = 7
I've tried to make an array of all the last names
PHP Code:

$last_name_array = array();
foreach ($results as $key => $value) {        
    $last_name_array[]=$value[graph_user_hpcx_last_name];
}
sort($last_name_array);
$last_name_array=array_unique($last_name_array); 



then looping through all my results to see if it matches a name, if so print the units, if not print 0 but I get way two sets for each name (cause of the 6 and 7 month)

PHP Code:

foreach ($last_name_array as $key => $value) {            
         foreach ($results as $key => $value1) {   
             if  ($value == $value1[graph_user_hpcx_last_name])  {
                if ($value1[graph_user_hpcx_Accounting_Year]== 2006 && $value1[graph_user_hpcx_Accounting_Month] == 6) {
              echo "$value1[graph_user_hpcx_AllocationUnits]<br />\n";
                }  else {
                echo "0";
               }
             }
         }
    } 



Any suggestions on how best to get this? Been reading all I can and am still stumped!
Last edited by LuciWiz : 20-Sep-2006 at 08:20. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 28-Sep-2006, 20:09
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: getting associative array to output correct including missing value


Are you still having trouble getting the loop to work right?
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 29-Sep-2006, 02:42
bouton bouton is offline
New Member
 
Join Date: Sep 2006
Posts: 2
bouton is on a distinguished road

Re: getting associative array to output correct including missing value


never figured it out- so went in and set the column in the database to 0
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bit stuffing agnostos C Programming Language 17 12-Sep-2006 20:10
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 19:31
C++ PhoneBook marita C++ Forum 46 12-Jun-2005 12:10
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 21:26
using vector or array oshiotse C++ Forum 4 16-Apr-2004 10:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:00.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.