如何用angular和php计算?

坦雅

我正在用angular和php构建一个项目。我的数据库中有一个“库存”表,可以检索表中的所有数据。我想计算总计“数量”列并显示总计,但是我不知道该怎么办。谁能帮忙吗?

的PHP:

<?php
  header('Content-Type: text/html; charset=utf-8');
  $connection = mysqli_connect('localhost','root','','hamatkin');

  mysqli_query($connection,"SET character_set_client = utf8");
  mysqli_query($connection,"SET character_set_connection = utf8");
  mysqli_query($connection,"SET character_set_results = utf8");

  if(!$connection){
    die("couldnt connect".mysqli_error);
  }

  $query="SELECT `stock_id`,`product_name`,`description`,`quantity` FROM `stock`";
  $queryResult = $connection->query($query);
  $queryResult2 = array();
  if( $queryResult->num_rows>0){
    while($row = $queryResult->fetch_assoc()){
      $queryResult2[] = $row;
    }
  }
  $queryResult3 = json_encode($queryResult2);
   echo json_encode($queryResult3);
?>

HTML:

    </div>

  <div class="table-responsive">
    <table  class="customer-list table table-striped">
      <thead>
        <tr>
          <!-- <th>#</th> -->
          <th class="Column-Header">קוד מוצר</th>
          <th class="Column-Header">שם מוצר</th>
          <th class="Column-Header">תיאור מוצר</th>
          <!-- <th class="Column-Header">כמות במלאי</th>
          <th class="Column-Header">סה"כ</th> -->


        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="item in stockReport" ng-init="setTotals(item)">
              <td>{{item.ProductName}}</td>
              <td>{{item.quantity}}</td>
          </tr>

      <tfoot>
          <tr class="bg-warning">
              <td>Totals</td>
              <td>{{invoiceCount}}</td>
              <td></td>
          </tr>

        </tfoot>


      </tbody>
    </table>

  </div>

控制器:

"use strict";
angular.module('dataSystem').controller('reportsCtrl', function ($scope, $route, $location, $http) {
  $http({method:'GET', url:'api/reports-tab/stock-report.php/'})
      .then(function(response) {
        var arr = JSON.parse(JSON.parse(response.data));
        $scope.v = arr;


      })

      // This will log you the error code and trace, if there is an error.

      .catch(function(err) {
        console.log('err', err)
      });


      $scope.setTotals = function(item){
          if (item){
              item.total = item.quantity * item.unitCost;
              $scope.invoiceCount += item.quantity;

          }
      }



});
萨耶塔兰(Sajeetharan)

您可以在JS中使用以下功能,

JS:

$scope.setTotals = function(item){
        if (item){
            item.total = item.quantity * item.unitCost;
            $scope.invoiceCount += item.quantity;

        }
    }

看法

  <tr ng-repeat="item in items" ng-init="setTotals(item)">
            <td>{{item.ProductName}}</td>
            <td>{{item.quantity}}</td>                 
        </tr>
    </tbody>
    <tfoot>
        <tr class="bg-warning">
            <td>Totals</td>
            <td>{{invoiceCount}}</td>
            <td></td>                   
        </tr>

Working App

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何用angular和php计算?

来自分类Dev

如何用php逃脱“和”?

来自分类Dev

如何用html和php上传图片?

来自分类Dev

在计算单字LM时如何用<s>和</ s>处理?

来自分类Dev

如何用php打破印地语字符串并计算字符串中有多少字母和元音

来自分类Dev

如何用php计算数组空值?

来自分类Dev

如何用python计算大数?

来自分类Dev

如何用sympy计算argmax?

来自分类Dev

如何用sympy计算argmax?

来自分类Dev

如何用逗号计算金额

来自分类Dev

如何用Highcharts和大量动态数据构造Angular

来自分类Dev

如何用PHP和GD解决字体变形问题

来自分类Dev

如何用PHP更改mp3标签和照片?

来自分类Dev

如何用preg_replace和PHP替换特殊字符?

来自分类Dev

如何用php和mysql生成md5

来自分类Dev

如何用PHP计算带有PHP的增值税百分比的总数

来自分类Dev

如何在PHP中计算累计和?

来自分类Dev

如何用熊猫计算百分比和累积百分比

来自分类Dev

如何用numpy计算向量和矩阵的“克罗内克积”

来自分类Dev

如何用从行名和列名计算出的值填充R矩阵?

来自分类Dev

如何用 XML 和 XSLT 做一个计算器

来自分类Dev

你如何用awk替换sed和wc?(计算目录中的名称)

来自分类Dev

如何用php计算非英语句子中的单词数?

来自分类Dev

如何用熊猫计算组元素的数量

来自分类Dev

如何用键计算数组值

来自分类Dev

如何用ng-repeat计算Total

来自分类Dev

如何用Java计算结果?

来自分类Dev

如何用矩阵进行指数计算?

来自分类Dev

如何用位域计算结构的大小?