Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show all division wise total in mysql
    primarykey
    data
    text
    <p>How can I show all division wise separate total?</p> <p>Example:</p> <p>I want data like this </p> <pre><code> --------------------------------------------------------------- CARD NO NAME CAR NO DIVISION DATE AMOUNT --------------------------------------------------------------- 80351 MANWATERTANKER 4454HM 102 2013-9-30 95.000 60759 TIPPER 2368BK 102 2013-8-31 77.500 64545 MFASIL 3334HG 102 2013-9-30 20.000 56565 XYAZ 93F68K 102 2013-8-31 55.000 --------------------------------------------------------------- Total 247.500 --------------------------------------------------------------- CARD NO NAME CAR NO DIVISION DATE AMOUNT --------------------------------------------------------------- 90178 ATEEQ 8931RR 105 2013-7-31 551.000 43325 USMAN 6732YY 105 2013-6-30 12.500 55598 ALAAM 4631TT 105 2013-7-31 158.000 --------------------------------------------------------------- Total 721.500 --------------------------------------------------------------- CARD NO NAME CAR NO DIVISION DATE AMOUNT --------------------------------------------------------------- 40678 FATHISALIM 1632AM 103 2013-6-30 454.440 --------------------------------------------------------------- Total 454.440 ----------------------------------------------------------------- AND OVERALL TOTAL 1423.440 ----------------------------------------------------------------- </code></pre> <p>and now it is showing like this</p> <pre><code>--------------------------------------------------------------- CARD NO NAME CAR NO DIVISION DATE AMOUNT --------------------------------------------------------------- 80351 MANWATERTANKER 4454HM 102 2013-9-30 95.000 60759 TIPPER 2368BK 102 2013-8-31 77.500 40678 FATHISALIM 1632AM 103 2013-6-30 454.440 90178 ATEEQ 8931RR 105 2013-7-31 551.000 64545 MFASIL 3334HG 102 2013-9-30 20.000 56565 XYAZ 93F68K 102 2013-8-31 55.000 43325 USMAN 6732YY 105 2013-6-30 12.500 55598 ALAAM 4631TT 105 2013-7-31 158.000 --------------------------------------------------------------- Total 1423.440 </code></pre> <p>and this is my code:</p> <pre><code>&lt;?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("car", $con); function formatMoney($number, $fractional=false) { if ($fractional) { $number = sprintf('%.2f', $number); } while (true) { $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number); if ($replaced != $number) { $number = $replaced; } else { break; } } return $number; } $a=$_POST['from']; $b=$_POST['to']; echo "&lt;span align='center' class='style2'&gt;Report For The Period Of $a to $b&lt;/span&gt;"; echo "&lt;div id='non-printable'&gt;&lt;table class='hovertable' border='1' cellpadding='10'&gt;"; echo "&lt;tr&gt; &lt;th&gt;CardNo&lt;/th&gt; &lt;th&gt;NAME/th&gt;&lt;th&gt;CARNO&lt;/th&gt;&lt;th&gt;Division&lt;/th&gt; &lt;th&gt;Date&lt;/th&gt;&lt;th&gt;AMOUNT&lt;/th&gt;&lt;/tr&gt;"; // get results1 from database $result1 = mysql_query("SELECT * FROM fuel where date BETWEEN '$a' AND '$b' order by division ASC"); while($row = mysql_fetch_array($result1)) { // echo out the contents of each row into a table echo "&lt;tr&gt;"; echo '&lt;td&gt;' . $row['cardno'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['drivernamefuel'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['carno'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['division'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['date'] . '&lt;/td&gt;'; echo '&lt;td&gt;' . $row['amount'] . '&lt;/td&gt;'; echo "&lt;/tr&gt;"; //Increment the value of the Total_total variable //by the salary value of one row till the while loop finishes $Total_amount=$Total_amount+$row['amount']; } echo "&lt;tr&gt;"; echo '&lt;td&gt;Total&lt;/td&gt;'; echo '&lt;td&gt;&lt;/td&gt;'; echo '&lt;td&gt;&lt;/td&gt;'; echo '&lt;td&gt;&lt;/td&gt;'; echo '&lt;td&gt;&lt;/td&gt;'; echo '&lt;td&gt;' . $Total_amount .'&lt;/td&gt;'; echo "&lt;/tr&gt;"; // close table&gt; echo "&lt;/table&gt;"; mysql_close($con); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload