希望添加一列并在最后显示结果


Looking to add a column and show results in end?

我希望添加从MySQL数据库获取的列结果。此外,我希望按中心和医学对结果进行分组。

我想在 HTML 表中的新行中显示下一个结果。再次检查此内容

       SNoMedicineName  QTY Center
   3    7            3  Bhop
   4    7            3  Bhop
   5    7            3  Bhop
   6    1            2  Bhop
   TOTAL QTY2 TOTAL QTY9 
   6Medicine1CenterBhopalQTY2 3Medicine7CenterBhopalQTY3   
   //Here i am looking for sno to 1 med name to 7 qty to 9 cent to bhop
   then    sno to 2 med name to 1 qty to 2 cent to bhop

我的代码是

    <?php
include_once('db.php');
$sql = "SELECT * FROM medical_new  ";
if(isset($_Post['submit']));
{
$cent=$_POST['center'];
$sql .= "where center= '{$cent}'";
}

$query=mysql_query($sql) or die (mysql_err());

?>
<table border='1'>
<tr>
<th><b>SNo</b></th>
<th><b>MedicineName</b></th>
<th><b>QTY</b></th>
<th><b>Center</b></th>
</tr>
<?php
while( $row = mysql_fetch_array($query) )
 {
  echo "<tr>"; 
echo "<td>" . $row['CustomerID'] . "</td>";
echo "<td>" . $row['MedicineName'] . "</td>";
echo "<td>" . $row['Qty'] . "  </td>";
echo "<td>" . $row['Center'] . "</td>";
  echo "</tr>";
}
echo "</table>";
?>

有人可以给我一些关于如何做到这一点的提示或建议吗?谢谢。

桌子

    CustomerID  MedicineName    Date    Qty     RRP     Net RRP     MRP Price   Net MRP     Center
    1       1           0000-00-00   3      250     750             360        1080     2
    2       3           0000-00-00   3      111     333              211        633     3
    3       7           0000-00-00   3      222     666              211       633     Bhop
    4       7           10/10/2013   3      222     666              211       633      Bhop

这会有所帮助

<table border='1'>
<tr>
<th><b>SNo</b></th>
<th><b>MedicineName</b></th>
<th><b>QTY</b></th>
<th><b>Center</b></th>
</tr>
<?php
while( $row = mysql_fetch_array($query) )
 {
  echo "<tr>"; 
echo "<td>" . $row['CustomerID'] . "</td>";
echo "<td>" . $row['MedicineName'] . "</td>";
echo "<td>" . $row['Qty'] . "  </td>";
echo "<td>" . $row['Center'] . "</td>";
  echo "</tr>";
}
////
 $sql2 = "SELECT *,SUM(Qty)AS totalQty  FROM medical_new where center= '{$cent}' GROUP BY MedicineName";
 $query2=mysql_query($sql2) or die (mysql_err());
 while( $row = mysql_fetch_array($query) )
 {
 echo "<tr>"; 
echo "<td>" "</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL QTY" . $row['totalQty'] . "  </td>";
  echo "</tr>";
}
echo "</table>";
?>