Php 如何对在模型页面中创建的表进行计算

Php 如何对在模型页面中创建的表进行计算,php,codeigniter,Php,Codeigniter,这是用于获取数据和数据的模型代码 以表格格式创建 我的问题是我是如何计算的 如数量*值和显示在值文本中 在模型代码中,我在该表中创建了一个表,该表如何计算。。。。。。。 如何计算在模型页面中创建的表。从下面的代码中更新foreach循环代码 public function fetch_item($item) { $this->db->where("pgroup",$item); $this->db->select('*'); $this->db-&g

这是用于获取数据和数据的模型代码 以表格格式创建

我的问题是我是如何计算的 如数量*值和显示在值文本中 在模型代码中,我在该表中创建了一个表,该表如何计算。。。。。。。
如何计算在模型页面中创建的表。

从下面的代码中更新foreach循环代码

public function fetch_item($item)
{
   $this->db->where("pgroup",$item);
   $this->db->select('*');
  $this->db->from('itemmaster');
   $this->db- 
 >join('pgroup','pgroup.pgroupid 
     = itemmaster.catcode','left 
 outer');
     $query_result = $this->db->get()- 
    >result();

        //pass query result as html

        $output = '<table class="table 
      table- 
     striped table-bordered table- 
        hover">
        <thead>
        <tr>
          <th>Product Name</th>
            <th>Rate</th>
           <th>Qty</th>
        <th>amount</th>
      </tr>
     </thead>
  <tbody>';

      if($query_result !='false'){

       foreach ($query_result as $key 
         => 
         $value) {

       $output .='<tr>
          <td>'.$value- 
             >product_name.'</td>
         <td><input style="width:100px"  
         name="rate" type="text" 
    class="form- 
     control input-xs"   value=""></td>
     <td><input style="width:100px"  
      name="qty" type="text" 
       class="form- 
       control input-xs"    value=""> 
    </td>
      <td><input style="width:100px"  
         name="amount" type="text" 
        class="form- 
       control input-xs"    value=""> 
        </td>
      </tr>';
       }
}

       $output .="</tbody>
  </table>";

 echo $output;

  }
将下面的代码添加到您的视图页面中,确保jquery min lode先于此脚本

$i=0;
foreach ($query_result as $key => $value) {

    $output .='<tr>
          <td>'.$value->product_name.'</td>
         <td><input style="width:100px" name="rate" type="text" class="form-control input-xs" value="" id="rate_'.$i.'" onchange="calculate('.$i.')"></td>
         <td><input style="width:100px" name="qty" type="text" class="form-control input-xs" value="" id="qty_'.$i.'" onchange="calculate('.$i.')"> </td>
         <td><input style="width:100px" name="amount" type="text" class="form-control input-xs" value="" id="amount_'.$i.'"> 
         </td></tr>';
   $i++;
}

先生,我已经给出了数量和速率动态,您需要javasript或jquery调用模糊数量输入,然后计算总数,这是我的prblm先生,我在查看页面中是这样写的。。因为这个表是在模型页面中创建的,该页面以表的形式从数据库和视图中获取数据。好的,我将给出代码。您想在用户添加该产品的数量和费率时更新总金额,对吗?让我们。
<script type="text/javascript">
  function calculate(id){
    var rate=$("#rate_"+id).val();
    var qty=$("#qty_"+id).val();
    if(qty=="")
        qty=0;
    if(rate=="")
        rate=0;
    var total=rate*qty;
    $("#amount_"+id).val(total);

  }
</script>