didgydont Posted February 16, 2008 Share Posted February 16, 2008 hi all im trying to add the total of a column not the row i had a look around in google and found how to add row and also found http://www.kksou.com/php-gtk2/articles/add-a-total-row-to-the-end-of-GtkTreeView---Part-1.php but could not folow or understand the code it errored out when i copied all the code i think it had some thing to do with not haveing Gtk basicly all i want is the total of oweing for example thank you for your time <?php $con = mysql_connect("localhost","*******","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("*********", $con); include("toolbar.php"); // Begin your table outside of the array echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td><b>  Cost</b></td> <td><b>  Deposit</b></td> <td><b>  Owing</b></td> <td><b>  Ordered</b></td> </tr>"; // Define your colors for the alternating rows $color1 = "#F0F8FF"; $color2 = "#CCFFFF"; $row_count = 0; // Perform an statndard SQL query: $result = mysql_query("SELECT * FROM jobs ORDER BY jobnumber"); // We are going to use the "$row" method for this query. This is just my preference. while($row = mysql_fetch_array($result)) { $customer = $row['clientid']; $cost = $row['cost']; $depos = $row['deposit']; $oweing = ($cost - $depos); $result2 = mysql_query("SELECT * FROM clients WHERE Uid='$customer'"); $row2 = mysql_fetch_array($result2); $status = $row['status']; $jobno = $row['jobnumber']; $custname = $row2['FirstName'] ." ". $row2['LastName']; $item = $row['item']; $orderd = $row['ordered']; $oweing2 = number_format($oweing,2); $cost2 = number_format($cost,2); $depos2 = number_format($depos,2); /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ($row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. echo "<tr> <td align=\"right\" bgcolor=\"$row_color\">  \$$cost2</td> <td align=\"right\" bgcolor=\"$row_color\">  \$$depos2</td> <td align=\"right\" bgcolor=\"$row_color\">  \$$oweing2</td> <td bgcolor=\"$row_color\">  $orderd</td> </tr>"; // Add 1 to the row count $row_count++; } // Close out your table. echo "</table>"; mysql_close($con); ?> code] Link to comment https://forums.phpfreaks.com/topic/91357-solved-column-total/ Share on other sites More sharing options...
beebum Posted February 16, 2008 Share Posted February 16, 2008 http://us3.php.net/manual/en/function.array-sum.php Look at the comment dated 29-Jan-2008 07:31 (currently at the top). Link to comment https://forums.phpfreaks.com/topic/91357-solved-column-total/#findComment-468153 Share on other sites More sharing options...
didgydont Posted February 16, 2008 Author Share Posted February 16, 2008 i ended up doing this <?php $con = mysql_connect("********","************","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("*************", $con); include("toolbar.php"); // Begin your table outside of the array echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td><b>  Cost</b></td> <td><b>  Deposit</b></td> <td><b>  Owing</b></td> <td><b>  Ordered</b></td> </tr>"; // Define your colors for the alternating rows $color1 = "#F0F8FF"; $color2 = "#CCFFFF"; $row_count = 0; // Perform an statndard SQL query: $result = mysql_query("SELECT * FROM jobs ORDER BY jobnumber"); // We are going to use the "$row" method for this query. This is just my preference. while($row = mysql_fetch_array($result)) { $customer = $row['clientid']; $cost = $row['cost']; $depos = $row['deposit']; $oweing = ($cost - $depos); $result2 = mysql_query("SELECT * FROM clients WHERE Uid='$customer'"); $row2 = mysql_fetch_array($result2); $result3 = mysql_query("SELECT SUM(cost) FROM jobs"); $row3 = mysql_fetch_array($result3); $result4 = mysql_query("SELECT SUM(deposit) FROM jobs"); $row4 = mysql_fetch_array($result4); $status = $row['status']; $jobno = $row['jobnumber']; $custname = $row2['FirstName'] ." ". $row2['LastName']; $item = $row['item']; $orderd = $row['ordered']; $oweing2 = number_format($oweing,2); $cost2 = number_format($cost,2); $depos2 = number_format($depos,2); $totcost = $row3['SUM(cost)']; $totdepos = $row4['SUM(deposit)']; $totoweing = ($totcost - $totdepos); $totoweing2 = number_format($totoweing,2); $totcost2 = number_format($totcost,2); $totdepos2 = number_format($totdepos,2); /* Now we do this small line which is basically going to tell PHP to alternate the colors between the two colors we defined above. */ $row_color = ($row_count % 2) ? $color1 : $color2; // Echo your table row and table data that you want to be looped over and over here. echo "<tr> <td align=\"right\" bgcolor=\"$row_color\">  \$$cost2</td> <td align=\"right\" bgcolor=\"$row_color\">  \$$depos2</td> <td align=\"right\" bgcolor=\"$row_color\">  \$$oweing2</td> <td bgcolor=\"$row_color\">  $orderd</td> </tr>"; // Add 1 to the row count $row_count++; } // Close out your table. // Make a MySQL Connection //$query = "SELECT type, SUM(cost) FROM jobs"; //$result2 = mysql_query($query) or die(mysql_error()); // Print out result //while($row = mysql_fetch_array($result)){ //echo "<tr><td>Total \". \" = $\". $row['SUM(cost)']</td></tr> "; //} echo "</table>"; /*$result3 = mysql_query("SELECT SUM(cost) FROM jobs"); while($row3 = mysql_fetch_array($result3)) { $totcost = $row3['SUM(cost)']; } $result4 = mysql_query("SELECT SUM(deposit) FROM jobs"); while($row4 = mysql_fetch_array($result4)) { $totdepos = $row4['SUM(deposit)']; } */ echo " <B> $$totcost2  $$totdepos2  $$totoweing2 </B>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/91357-solved-column-total/#findComment-468163 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.