Jump to content

bouton

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bouton's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. As I said - works perfect. I extended it even just a bit further so I could have a campaign label in a status colored box. Thanks again. [code] <style> TD.P {     background-color: #FCC;     text-align: center; } TD.M {     background-color: #CCC;     text-align: center; } TD.F {     background-color: #CFC;     text-align: center; } </style> <?php $results = $dbq->queryGetResults(); $calendar = array(); foreach ($results as $record) {     list ($inst, $d1, $d2, $campaign, $status) = array_values($record);     $m1 = date('n', strtotime($d1));     $m2 = date('n', strtotime($d2));         if (!isset($calendar[$inst])) $calendar[$inst] = array();         for ($m = $m1; $m <= $m2; $m++) {         $calendar[$inst][$m][0] = $campaign;         $calendar[$inst][$m][1] = $status;     } } /** * output the calendar array data */ echo '<table border="1" align="left">'; echo "\n<tr><td>Instrument</td>\n"; for ($i=1; $i<=12; $i++) {              // for the twelve months of the year     $t = mktime(0,0,0, $i, 1, 2006);  // set $t to hour minute second month day year     $m = date('M', $t);                  // set the month column name to three letter month eg Jan Feb Mar     echo "<td>$m</td>";                // make the first row the column header of the list of months } echo "</tr>\n"; // data foreach ($calendar as $inst => $item) {     echo "<tr><td>$inst</td>\n";          // put the instrument name in the first column     for ($m=1; $m <= 12; $m++) {        // for every month that there is data - print it out                                                       // with status as class, campaign as column       echo (isset($item[$m])) ? "<td class='{$item[$m][1]}'>{$item[$m][0]}</td>" : '<td>&nbsp;</td>';     }     echo "</tr>\n"; } echo "</table>\n"; ?>[/code]
  2. THANK YOU SO MUCH. Worked almost perfect out of the box. I just had to change [code]list ($inst, $d1, $d2, $status) = $record;[/code] to [code]list ($inst, $d1, $d2, $status) = array_values($record);[/code] because of the way my array was coming out of the database. A perfect xmas present. K PS - you are the barry andrews of the baagrid - I have used that in the past for crosstabs - it's great. Thanks again. ;D
  3. I almost have it but can't get those last few inches... I have a database of events [code] table instrument_planning; id instrument start_date (eg 2006-01-01) start_Month = Month(start_date) end_date (eg 2006-11-1) status [/code] Data would look like this [code] "instrument 1","2006-01-01","2006-01-31","Proposed" "instrument 1","2006-02-01","2006-04-30","Funded" "instrument 2","2006-02-01","2006-02-28","Funded" "instrument 3","2006-01-01","2006-01-31","Proposed" "instrument 3","2006-03-01","2006-03-31","Proposed" [/code] What I want it to look like is [table] [tr][td]Instrument[/td][td]Jan[/td][td]Feb[/td][td]Mar[/td][td]Apr[/td][td]May[/td][td]Jun[/td][td]Jul[/td][td]Aug[/td][td]Sep[/td][td]Oct[/td][td]Nov[/td][td]Dec[/td][/tr] [tr][td]instrument 1[/td][td]Proposed[/td][td]Funded[/td][td]Funded[/td][td]Funded[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 2[/td][td]-[/td][td]Funded[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 3[/td][td]Proposed[/td][td]-[/td][td]Proposed[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [/table] where each of the boxes "Proposed" or "Funded" will be a different color, set by CSS (e.g. class="proposed" which I couldn't do with this editor I can only get it to put each of the status on a separate line [table] [tr][td]Instrument[/td][td]Jan[/td][td]Feb[/td][td]Mar[/td][td]Apr[/td][td]May[/td][td]Jun[/td][td]Jul[/td][td]Aug[/td][td]Sep[/td][td]Oct[/td][td]Nov[/td][td]Dec[/td][/tr] [tr][td]instrument 1[/td][td]Proposed[/td][td]Funded[/td][td]-[/td][td]Funded[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 1[/td][td]Proposed[/td][td]-[/td][td]Funded[/td][td]Funded[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 2[/td][td]-[/td][td]Funded[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 3[/td][td]Proposed[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [tr][td]instrument 3[/td][td]-[/td][td]-[/td][td]Proposed[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][td]-[/td][/tr] [/table] I can't that looping to work. my code [code] $results = $dbq->queryGetResults(); echo '<table border="1">'; echo '<tr><th colspan="14" align="center">2006</th></tr>'."\n"; echo '<tr><td>Institute</td><td>Instrument</td><td>Jan</td><td>Feb</td><td>Mar</td><td>Apr</td><td>May</td><td>Jun</td><td>Jul</td><td>Aug</td><td>Sep</td><td>Oct</td><td>Nov</td><td>Dec</td></tr>'."\n"; foreach ($results as $result)  {       if ($result['status'] == "F") {           $CSSRow =' class="funded"';       } elseif ($result['status'] == "P") {           $CSSRow =' class="proposed"';       } if ($result['start_Year']=="2006") {       echo '<tr>';       echo "<td>".$result['institute']."</td>";       echo "<td>".$result['instrument']."</td>";       if ($result['start_Month']=="1") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';            } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="2") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="3") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="4") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="5") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                    } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="6") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['UFAM_start_Month']=="7"){         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="8") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="9") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="10") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                  } else {         echo "<td>&nbsp;</td>";       }       if ($result['start_Month']=="11") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';                    } else {         echo '<td>&nbsp;</td>';       }       if ($result['start_Month']=="12") {         echo '<td'.$CSSRow.'>'.$result['start_date'].' ' .$result['status'] .'</td>';            } else {         echo "<td>&nbsp;</td>";       }       echo '</tr>';     } // end for 2006 }  // end for each result echo '</table>'."\n"; [/code] Probably an array of months or something? Anyway, if you can help me out - appreciated.
  4. 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         ) [/code] 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 [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);      [/code] 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) [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";               }             }         }     } [/code] Any suggestions on how best to get this? Been reading all I can and am still stumped!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.