Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法显示/计算一组文本字段的总值-angular js html php_Php_Html_Angularjs_Forms - Fatal编程技术网

无法显示/计算一组文本字段的总值-angular js html php

无法显示/计算一组文本字段的总值-angular js html php,php,html,angularjs,forms,Php,Html,Angularjs,Forms,我有一个简单的表单,它有“total”字段和另一个total字段(这是所有“total”字段的总和) “总计”字段根据数量和单位成本字段的值进行计算,即qty0*unitcost0=total0、qty1*unitcost1=total1,依此类推。。请注意,数量和金额来自数据库 我希望总的总数可以像total0+total1+total2……这样实时计算 这是我的代码(如果这段代码对某些人来说很凌乱,很抱歉,但我只是一个编程初学者) 我的ng应用程序位于body标签中,我的ng控制器位于div

我有一个简单的表单,它有“total”字段和另一个total字段(这是所有“total”字段的总和)

“总计”字段根据数量和单位成本字段的值进行计算,即qty0*unitcost0=total0、qty1*unitcost1=total1,依此类推。。请注意,数量和金额来自数据库

我希望总的总数可以像total0+total1+total2……这样实时计算

这是我的代码(如果这段代码对某些人来说很凌乱,很抱歉,但我只是一个编程初学者) 我的ng应用程序位于body标签中,我的ng控制器位于div中

<?php
        echo '
           <form name="editpo" id="editpo" method="post" action="poeditprocess.php">
            <table>
                <tr>
                    <th colspan="1">Stock No.</th>
                    <th colspan="1"> Unit </th>
                    <th colspan="5">Description</th>
                    <th colspan="1">Quantity</td>
                    <th colspan="1">Unit Cost</th>
                    <th colspan="1">Amount</th>
                </tr>
            </table>
            <table id="items">';


            //print the item desc, unit, qty and unit cost 
            $ctr02 = 1;
            $tamt = 0;

            for ($i=0; $i < $ctritem; $i++)
            {
                $amt = $qty[$i] * $unitc[$i];
                $tamt = $tamt + $amt;

                $unitc[$i] = number_format($unitc[$i], 2, '.', ',');
                $amt = number_format($amt, 2, '.', ',');
                //initialize the qty and unitcost with the values fro db                
                echo '<tr ng-init="qty'.$i.'='.$qty[$i].'; cost'.$i.'='.$unitc[$i].';">';
                                echo "
                                            <td id='amt'>".$ctr02."</td>
                                            <td> <input type='text' name='unit[".$i."]' value='".$poitemunit[$i]."' required/></td>
                                            <td colspan='3'><textarea rows='2' name='desc[".$i."]' required>".$poitemdesc[$i]."</textarea></td>";
                                echo '
                                            <td><input type="number" name="qty'.$i.'"  id="qty'.$i.'" min="0" max="10000" ng-model="qty'.$i.'" required /></td>
                                            <td><input type="number" name="unitcost" ng-model ="cost'.$i.'" step="any" min="0" required /></td>

                                            <td><input type="text" name="amt'.$i.'" id="amt'.$i.'" step="any" value="{{(qty'.$i.' * cost'.$i.') | currency : \'P \' : 2}}" disabled/></td>

                                        </tr>';

                            $ctr02++;
                            }
                            echo "
                        </table>";

                    echo "  <table>";
            //this is the overall total
                    echo '<td><input type="text" name="tamt" id="tamt" value="{{(';
                                $x=0;
                                while($x<=$ctritem){
                                echo '(qty'.$x.' * cost'.$x.')';
                                    if($x<$ctritem){
                                    echo '+';
                                    }
                                $x++;

                                }

                    echo ')| currency : \'Php \' : 2}}" disabled/></td>
                            </tr>';

                    echo "</table> 
                    </form>";
                    ?>

在for循环中,将previoius行更改为
然后在for循环之外声明

$grandtotal = 0 
在for循环中,将$total$i添加到$grandtotal,其中:

$grandtotal += $total$i;

@莱洛:谢谢你的回答,我非常感谢。然而,我仍然不能让它工作。但是经过多次尝试,我想我会重写整个代码片段,然后它就成功了。(此处插入大笑,因为我不知道第一个代码中的错误)

因此,为了所有将遇到与我相同问题(或与我的问题密切相关)的人的利益,以下是代码:

//this is the overall total
                    echo '<td><input type="text" name="tamt" id="tamt" value="{{';
                        $ctrt = 0;      
                        while ($ctrt<$i)
                        {
                            echo'(qty'.$ctrt.' * cost'.$ctrt++.')';
                            if($ctrt<$i){
                                echo '+';
                            }

                        }   

                    echo '| currency : \'Php \' : 2}}" disabled/></td>';
//这是总数
回声';
$grandtotal += $total$i;
//this is the overall total
                    echo '<td><input type="text" name="tamt" id="tamt" value="{{';
                        $ctrt = 0;      
                        while ($ctrt<$i)
                        {
                            echo'(qty'.$ctrt.' * cost'.$ctrt++.')';
                            if($ctrt<$i){
                                echo '+';
                            }

                        }   

                    echo '| currency : \'Php \' : 2}}" disabled/></td>';