Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
how to SUM output of certain field result
Old 06-21-2009, 10:30 PM how to SUM output of certain field result
Junior Talker

Posts: 3
Name: sasika
Trades: 0
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);
?>
__________________

Please login or register to view this content. Registration is FREE
sasikashiroshi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-22-2009, 01:37 AM Re: how to SUM output of certain field result
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
change your query from
PHP Code:
$result mysql_query"select * from dt_tb where driver='$chooser' and vehicleno='$chooser2' and month(startdate) between '$chooser3' and '$chooser3' " 
to
PHP Code:
$result mysql_query"select *, sum(drop) as dropSum from dt_tb where driver='$chooser' and vehicleno='$chooser2' and month(startdate) between '$chooser3' and '$chooser3' " 
You will have a column named dropSum in your db result set, that will hold the sum of every rows in the table.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to how to SUM output of certain field result
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30572 seconds with 12 queries