Jezza22 Posted September 14, 2009 Share Posted September 14, 2009 I have a function that creates an Array to be used in JavaScript. The data supplied to the function is a php Array. The function works well, but I am trying to get a subtotal of key 3 where Key 0 is the same.... The php array looks as follows Array ( [0] => Array ( [0] => 7001 [1] => CASH [2] => SL_Receipts [3] => -431.25 [4] => 23/08/2009 [5] => JS ) [1] => Array ( [0] => 7001 [1] => CASH [2] => SL_Receipts [3] => -431.25 [4] => 23/08/2009 [5] => JS ) [2] => Array ( [0] => 7001 [1] => CASH [2] => SL_Receipts [3] => -431.25 [4] => 23/08/2009 [5] => JS ) [3] => Array ( [0] => 7001 [1] => BANK [2] => CASH [3] => -431.25 [4] => 23/08/2009 [5] => JS ) [4] => Array ( [0] => 7001 [1] => CASH [2] => SL_Receipts [3] => -431.25 [4] => 23/08/2009 [5] => JS ) [5] => Array ( [0] => 7003 [1] => CHEQUES [2] => CHQ 12345 [3] => -5000.00 [4] => 23/08/2009 [5] => JS ) [6] => Array ( [0] => 7003 [1] => CHEQUES [2] => CHQ 123456 [3] => -2000.00 [4] => 23/08/2009 [5] => JS ) ) Here is my attempt that is not working because, It fails to total all of key 3 and only sub totals once.. Please Help !! while ($array = mysql_fetch_array($result, MYSQL_NUM)) {$data[] = $array; } //echo '<pre>' . print_r($data, true) . '</pre>'; sort($data); function displayArrayData($arrayValues) { echo "["; $lastRowID = ''; //Iterrate through each record foreach ($arrayValues as $dataRow) { //Show blank row if this record is different ID than last if($dataRow[0]!=$lastRowID && $lastRowID != '') { if ($_GET[breakDown]=="YES") { echo '[],'; echo '["","","Total",'.$dataRow[3].'],'; echo '[],'; } else { } } //Set last ID value $lastRowID = $dataRow[0]; //Display current record echo ' ['; for ($a = 0; $a <= 8; $a++) { echo ' "'.$dataRow[$a].'",'; } echo '],'; } //Close the table echo '];'; } This displays the following... [ [ "7001", "CASH", "SL_Receipts", "-431.25", "23/08/2009", "JS", "", "", "",], [ "7001", "CASH", "SL_Receipts", "-431.25", "23/08/2009", "JS", "", "", "",], [ "7001", "CASH", "SL_Receipts", "-431.25", "23/08/2009", "JS", "", "", "",], [ "7001", "CASH", "SL_Receipts", "-431.25", "23/08/2009", "JS", "", "", "",], [], ["","","Total",-5000.00], [], [ "7003", "CHEQUES", "Chq 12345", "-5000.00", "24/08/2009", "JS", "", "", "",], [ "7003", "CHEQUES", "Chq 123456", "-2000.00", "15/08/2009", "JS", "", "", "",], ]; Quote Link to comment Share on other sites More sharing options...
Jezza22 Posted September 15, 2009 Author Share Posted September 15, 2009 Anybody on this one please.... Quote Link to comment Share on other sites More sharing options...
Jezza22 Posted September 19, 2009 Author Share Posted September 19, 2009 Resolved see http://www.phpfreaks.com/forums/index.php/topic,269762.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.