Zencart background reminder which products have 0 Inventory

Source: Internet
Author: User

Today, the director told me that due to customer needs, I had to perform some simple secondary development for zencart.

The general functions are as follows:

    • When the inventory of the product is 0, a prompt message is displayed on the front-end (due to this function, zencart already exists by default, so it is not modified)
    • Relevant information should also be prompted in the background to remind website operators

The final effect is as follows:

Code:
<! ----------------- Inventory warning 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"> inventory item warning quantity: <? PHP Echo   $ Units ;?> </Font> </div> <Div Class = "Row"> <font color = "red"> <Span Class = 'Left'> product name </span> <SpanClass = "Riyun"> product ID </span> </font> </div> <? PHP  While (! $ Res -> EOF ){  Echo "<Div class = 'row'> <SPAN class = 'left'> ". $ Res -> Fields ['products _ name']. "</span> <SPAN class = 'riyun'> ". $ Res -> Fields ['products _ id']. "</span> </div>" ;  $ Res -> Movenext ();} ?> </Div> <! --------------- Inventory warning End -->

Replace the aboveCodeAdd it to the index. php file in the background directory.

To calculate the total number of items whose inventory quantity is 0, use the aggregate function count (). However, if the preceding SQL statement is written as follows:

Select Count('Products_id')AsUnit, products_id, products_nameFrom". Table_products_description ."WhereProducts_idIn(SelectProducts_idFrom". Table_products ."WhereProducts_quantity=0)

In this way, only one result can be retrieved, because select count () only counts one result.

To perform count (*) Calculation for each result, count (*) should be used as a subquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.