apysan 11:17:11 | i have 2 tables 1. DLMAST 2. TRFILE DLMAST CONTAIN ID SUBCD NAME 1 A001 ASHOK GOOLI 2 A002 ARVIND DES PANDAY 3 D004 DINESH MODI etc etc TRFILE CONTAIN ID SUBCD BS QTY RATE 1 A001 B 100 100 2 A001 B 200 90 3 D004 S 25 70 4 K007 B 100 60 5 D004 B 50 50 6 E009 B 225 75 I WANT TO CREATE A TEMP TABLE AS UNDER SUBCD BS QTY RATE A001 B 100 100 A001 B 200 90 TOTAL 300 with diff color D004 B 25 70 D004 B 50 50 TOTAL 75 with diff color K007 B 100 60 TOTAL 100 with diff color E009 B 225 75 TOTAL 225 with diff color The main problum is that i can display the above list after sort on subcd but i dont know logic how to check-out wheter the next SUBCD is diff from last SUBCD in while( ) { } loop becouse we can not define and increment any variable inside { } loop so it simply display the above data in a table Please help me to get a table as under my code is as under =================== <HTML> <HEAD> </HEAD> <BODY> <?php $con = mysql_connect('localhost','root',''); if (!$con) { die('Could not connect: ' . mysql_error()); } print "<b><h1>Successfully Connected...........</h1></b>"; mysql_select_db("arjun_kaa_database", $con); $result = mysql_query("SELECT * FROM temptr"); ?> <div style="width: 760px; height: 340px; overflow: auto; padding: 5px"> <?php // $space=' '; print "<table id='customers'>"; print "<tr>"; print "<th>SERIAL</th>"; print "<th>TRADE_NO</th>"; print "<th>ELEVEN</th>"; print "<th>SCRIPT</th>"; print "<th>EQ / BE</th>"; print "<th>SCRIPT FULL NAME</th>"; print "<th>-F0-</th>"; print "<th>-F1-</th>"; print "<th>-F2-</th>"; print "<th>TERMINAL_ID</th>"; print "<th>-F3-</th>"; print "<th>B or S</th>"; print "<th>QUANTITY</th>"; print "<th>ORGI_RATE</th>"; print "<th>-F4-</th>"; print "<th>CLIENT_CODE</th>"; print "<th>-F5-</th>"; print "<th>NORMAL</th>"; print "<th>-F6-</th>"; print "<th>SEVEN</th>"; print "<th>DATE_TIME_1</th>"; print "<th>DATE_TIME_2</th>"; print "<th>ORDER_NO</th>"; print "<th>NIL</th>"; print "<th>MARGIN</th>"; while($ROW = mysql_fetch_array($result)) { print "<tr>"; print "<td>$ROW[0]</td>"; print "<td>$ROW[1]</td>"; print "<td>$ROW[2]</td>"; print "<td>$ROW[3]  </td>"; print "<td ALIGN=center>$ROW[4]</td>"; print "<td>$ROW[5] </td>"; print "<td ALIGN=center>$ROW[6]</td>"; print "<td ALIGN=center>$ROW[7]</td>"; print "<td ALIGN=center>$ROW[8]</td>"; print "<td ALIGN=center>$ROW[9]</td>"; print "<td ALIGN=center>$ROW[10]</td>"; print "<td ALIGN=center>$ROW[11]</td>"; print "<td ALIGN=RIGHT>$ROW[12]</td>"; print "<td ALIGN=RIGHT>$ROW[13]</td>"; print "<td>$ROW[14]</td>"; print "<td>$ROW[15]</td>"; print "<td>$ROW[16]</td>"; print "<td>$ROW[17]</td>"; print "<td>$ROW[18]</td>"; print "<td>$ROW[19]</td>"; print "<td>  $ROW[20]  </td>"; print "<td>  $ROW[21]  </td>"; print "<td>  $ROW[22]  </td>"; print "<td>$ROW[23]</td>"; print "<td>$ROW[24]</td>"; print "</tr>"; //print "</TABLE>"; } print "</table>"; mysql_close($con); ?> </div> </BODY> </HTML> |
smo1234 11-17-2011 | This may not exactly solve your problem but will give you idea on how to use group by sql command to get total in such cases. |