rusking Posted May 19, 2013 Share Posted May 19, 2013 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 19, 2013 Share Posted May 19, 2013 You could just do the math in the query. Quote Link to comment Share on other sites More sharing options...
rusking Posted May 19, 2013 Author Share Posted May 19, 2013 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 Quote Link to comment Share on other sites More sharing options...
rusking Posted May 19, 2013 Author Share Posted May 19, 2013 $Totals is the actual SQL script being ran 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.