2013-10-10 30 views
0

我期待添加從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 
+0

請描述你的表結構,包括鑰匙。 – geomagas

+0

[請不要使用mysql_ *函數](在新代碼中)(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。請改爲了解準備好的語句,並使用[pdo](https://wiki.php.net/rfc/mysql_deprecation)或[mysqli](http://stackoverflow.com/questions/tagged/mysqli)。 – zessx

+0

@zessx所以我應該在所有腳本中用mysqli替換mysql或者需要添加額外的代碼 – Eugene

回答

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

?> 
+0

謝謝,**我需要這個 – Eugene

+0

嗨@ Cristiana214,解析錯誤:語法錯誤,意外'*'如果我刪除他解析錯誤:語法錯誤,意外T_CONSTANT_ENCAPSED_STRING, – Eugene

+0

@geomagas it沒有工作 – Eugene

相關問題