doubomudichen0832 2013-12-15 00:50
浏览 12
已采纳

用于计算产品总数的脚本

Essentially, I am looking for a script to count the total number of products that I have in my store and then place this total inside a div.

  • 写回答

2条回答 默认 最新

  • dongpo0409 2013-12-15 03:08
    关注

    Seems like what you need is NOT javascript at all. If you are talking about OpenCart (as your title suggests), you need access to the total number of the products in your database (not in the page itself or DOM elements).

    The 'professional approach' will be to extend your model and controller files with the correct methods, but in case you are trying to avoid it (can't really recommend it) this is what you need to do.

    <div>
    <?php
      $query = $this->db->query("SELECT status FROM " . DB_PREFIX . "product WHERE status='1' ");
      $products_count = $query->rows ? count($query->rows) : 0;
      echo "Total products in store: " . $products_count;
    ?>
    </div>
    

    Again, since I'm a big fan of MVC structure, I'd recommend extending the controller and model to handle all the data, especially if you're going to use this in multiple view files. This way, you'll send the data to the view and all you'll have to do in your code will be:

    <div>
       echo "Total products in store: " . $products_count;
    </div>
    

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号