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