0

MySQL データベースから取得した qty 列の結果を追加しようとしています。また、結果をセンターと薬でグループ化することも考えています。

次の結果を 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
4

1 に答える 1

0

これは助けることができます

<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>";

?>
于 2013-10-10T07:28:44.267 に答える