列出具有部分相同产品编号的产品

时间:2017-01-12 07:07:35

标签: php html mysql

我想制作一个(html)产品列表,这些产品在完整站点后面具有相同的唯一编号(.)。例如,1.0001是周一售出的白面包2.0001是周二售出的白面包,依此类推。

现在我想列出一周内销售的所有白面包的总和。这就是我到目前为止所做的:

<?php   
  echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";  
  echo "<tr style='font-weight: bold;'>";  
  echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";  
  include("dbopen.php");  

  $result = mysql_query(
    "SELECT order_item_name, SUM( product_quantity ) 
     FROM wntl_virtuemart_order_items
     WHERE wntl_virtuemart_order_items.order_item_sku REGEXP  '0001$'
     AND order_status =  'U'");  

  while($row=mysql_fetch_array($result))  
  {  
    echo "<tr>";  
    echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";   
    echo "<td align='center' width='200'>" . $row['SUM(product_quantity)'] . "</td>";  
    echo "</tr>";  
  }  
  echo "</table>";  
?> 

输出:

注意:未定义索引:第17行* .php中的SUM(product_quantity)

1 个答案:

答案 0 :(得分:0)

试试这个:

<?php   
  echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";  
  echo "<tr style='font-weight: bold;'>";  
  echo "<td width='100' align='center'>Produkt</td><td width='100' align='center'>Baklijst</td>";  
  include("dbopen.php");  

  $result = mysql_query(
    "SELECT order_item_name, SUM( product_quantity ) AS Sum 
     FROM wntl_virtuemart_order_items
     WHERE wntl_virtuemart_order_items.order_item_sku REGEXP  '0001$'
     AND order_status =  'U'");  

  while($row=mysql_fetch_array($result))  
  {  
    echo "<tr>";  
    echo "<td align='center' width='200'>" . $row['order_item_name'] . "</td>";   
    echo "<td align='center' width='200'>" . $row['Sum'] . "</td>";  
    echo "</tr>";  
  }  
  echo "</table>";  
?>