how to SUM output of certain field result

2 replies
i got 3 combo box for choose driver,vehicleno and month.

OUTPUT
id date driver vehicleno drop

3 2005-06-06 sugu 3411 7
9 2007-01-25 sugu 3411 55
10 2007-01-15 sugu 3411 9
11 0000-00-00 sugu 3411 5


i want to SUM the output of this DROP field result. my coding is below, please someone can help me to find solution for this problem. My coding is below...please advise where to add in the fomula / coding.


index.php

<div align="left">
<p><img src="logo.gif" width="78" height="78">
</p>

<?php

// get variable after selecting something from the dropdown with name 'chooser'
$select = $_POST['select'];

// if something has been chosen
if (!empty($select)) {

// get the chosen value
$chooser = $_POST['chooser'];
$chooser2 = $_POST['chooser2'];
$chooser3 = $_POST['chooser3'];

// do whatever u want with that value
// for example output it
print "<B>Displaying Records for : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Driver $chooser</B><P>";
print "Vehicle No: $chooser2 <br>";
print "Month : $chooser3 <P>";

}

$db="b31_209797_pamross";
$link = mysql_connect("","","");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "select * from dt_tb where driver='$chooser' and vehicleno='$chooser2' and month(startdate) between '$chooser3' and '$chooser3' " )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=800 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
#field #output #result #sum
  • Profile picture of the author willmartinapj
    why not use SUM as in SUM?

    "SELECT SUM(drop) FROM dt_tb WHERE xxx='xxx' ";



    {{ DiscussionBoard.errors[939147].message }}
  • Profile picture of the author GB2008
    Right - putting it into the SQL query has to be the cleanest solution - but as you want the other info to, write your query as:

    SELECT *,sum(drop) FROM mytable WHERE......
    Signature
    {{ DiscussionBoard.errors[946462].message }}

Trending Topics