Jump to content

Array sum


rusking

Recommended Posts

OOo the 4 hours of cirlces iv travled on this one.

echo "<table border='1'>
<tr>
<th>Category</th>
<th>Value</th>
<th>Date</th>
<th>AddedUp</th>
</tr>";
$result = $con->query($Totals);
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row[0] . "</td>";
  echo "<td>" . $row[2] . "</td>";
  echo "<td>" . $row[1] . "</td>";
  echo "<td>" . array_sum($row[2]) . "</td>";
  echo "</tr>";
  }
echo "</table>";

Iv been tring to get it to  add all the vaules in row [2]. Below is the table but i can get teh "Values" added up.

 

 

I was wanting the total of "Value" to be at the bottom of the table but every combination i try to add or sum it up wont work. Yes i tried array_sum, might nt have used it correctly but did try. IF anyones got an idea please chime in :)

post-99869-0-45494200-1368972956_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/278172-array-sum/
Share on other sites

yea i know but iv kinda had to learn 3 languages at one time and its kinda big as it is 

<?php
//Site Directories
$rootsite='http://localhost:8888';
$ownersdebits='http://localhost:8888/owners/debits/';


//Connection Oriented
$con=mysqli_connect("localhost","root","root","BOYLEdanville");
//$con=mysqli_connect("BOYLEdanville.db.10675146.hostedresource.com","BOYLEdanville","JAMESbond007!!","BOYLEdanville");
$sumline="SELECT SUM(AMOUNT) AS value_sum FROM DEBITS";
//$TEST='AMOUNT';
//$sumline="SELECT SUM($TEST) AS value_sum FROM DEBITS";
//refer to http://www.tutorialspoint.com/mysql/mysql-sum-function.htm for above
//$Totals="SELECT TYPE, SUM() FROM DEBITS GROUP BY AMOUNT
//$Totals="SELECT '$_POST[TYPE]', SUM($_POST[COLUMN]) AS 'value_sum' FROM $_POST[TABLE] GROUP BY '$_POST[TYPE]'"; //working for all:|

if ($_POST[action] == ''){$Groupby='';} 
Else{$Groupby='GROUP BY TYPE';}
		
		
If ($_POST[element_1_3] > ''){$bydates="HAVING Date BETWEEN '$_POST[element_1_3]-$_POST[element_1_1]-$_POST[element_1_2] 00:00:00' AND '$_POST[element_2_3]-$_POST[element_2_1]-$_POST[element_2_2] 00:00:00'";}
Else{$bydates='';}
		
 //$Groupby="HAVING Date BETWEEN '$_POST[element_1_3]-$_POST[element_1_1]-$_POST[element_1_2] 00:00:00' AND '$_POST[element_2_3]-$_POST[element_2_1]-$_POST[element_2_2] 00:00:00'"






  $addedup="SELECT TYPE,date , SUM($_POST[COLUMN]) FROM $_POST[TABLE] WHERE TYPE='$_POST[CATEGORY]'";
  $Totals="SELECT TYPE,date , $_POST[action]($_POST[COLUMN]) FROM $_POST[TABLE] WHERE TYPE='$_POST[CATEGORY]' $Groupby $bydates";
  
// /SELECT TYPE,date , Amount FROM DEBITS WHERE TYPE = 'Cell Phone' having Date BETWEEN '2013-05-19 09:14:48' AND '2013-05-19 12:39:22';
// THE ABOVE WORKED!!!!!!!!!!!!
?>

lots of testing has been done in the past 24  hours as my A.D.D wont let me sleep and iv been learning PHP,MYSQLi and html

Link to comment
https://forums.phpfreaks.com/topic/278172-array-sum/#findComment-1430993
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.