今天,总监跟我说,由于客户需要,让我针对zencart进行些简单的二次开发。

    大体功能如下:

  • 当商品的库存为0的时候,在前台显示一个提示信息(由于这个功能,zencart默认就已经有了,所以就没去修改)
  • 在后台也应该提示相关信息,以提醒网站运营人员

最终的效果如下:

zencart后台提醒哪些商品的库存量为0

Code:

<!-----------------库存警告 start-->
<?php
    $sql="SELECT products_id,products_name,(SELECT count('products_id') FROM ".TABLE_PRODUCTS." WHERE ".TABLE_PRODUCTS.".products_quantity=0) AS unit FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id IN (SELECT products_id FROM ".TABLE_PRODUCTS ." WHERE products_quantity=0)";
    $res=$db->Execute($sql);
    $units=$res->fields['unit'];
?>

<div class="reportBox">
<div class="header"><font color="Red">库存商品警告数量:<?php echo $units;?></font></div>

<div class="row"><font color="Red"><span class='left'>产品名称</span><span class="rigth">产品ID</span></font></div>
<?php
    while(!$res->EOF){    
        echo "<div class='row'><span class='left'>".$res->fields['products_name']."</span><span class='rigth'>".$res->fields['products_id']."</span></div>";
        $res->MoveNext();
    }
?>
</div>
<!---------------库存警告 end-->

 将以上代码加入到后台目录的index.php文件中,即可

要计算库存数量为0的商品总数,需要使用到聚集函数count(),但是如果以上sql语句写成:

SELECT count('products_id') AS unit,products_id,products_name FROM ".TABLE_PRODUCTS_DESCRIPTION." WHERE products_id IN (SELECT products_id FROM ".TABLE_PRODUCTS ." WHERE products_quantity=0)

这样只能检索出一条结果,因为SELECT count() 仅对一个结果进行计数。

为了对每个结果进行都能进行count(*)计算,应该将count(*)作为子查询

相关文章:

  • 2021-09-10
  • 2021-09-21
  • 2021-06-25
  • 2022-01-14
  • 2021-04-22
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-06
  • 2021-10-16
  • 2021-06-28
  • 2021-09-14
  • 2021-11-19
  • 2021-07-31
相关资源
相似解决方案