This is a discussion on how to SUM output of certain field result within the PHP Programming forums, part of the Web Development category; I got 3 combo box for choose driver,vehicleno and month. OUTPUT id date driver vehicleno drop 3 2005-06-...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| 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 : &n bsp; &nbs p; 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); ?> |
|
#2
| |||
| |||
| Hi, First define a temp variable and set its value to zero. Now in the foreach loop, put a if condition that if the name of the field is "drop" then add its value in a temp variable. After the while is over you will see that the temp variable now has the sum of the drop field. Hope this helps. Cheers, ~Maneet |
|
#3
| |||
| |||
| Welcpme to here Last edited by arjkhanna : 09-25-2009 at 05:53 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I print my output? | S.Vinothkumar | C and C++ Programming | 2 | 10-13-2007 12:46 AM |
| export java program result into excel | chandana | Java Server Pages (JSP) | 1 | 09-14-2007 08:08 AM |
| Use of Text output value | Shanthi | Testing Tools | 1 | 08-25-2007 02:37 AM |
| Info on Supplement Result | vadivelanvaidyanathan | 0 | 05-22-2007 02:56 AM | |
| Any tool to get the Search Engine result | montyauto | Search Engine Optimization | 4 | 04-23-2007 12:10 AM |
Our Partners |