douping4436 2015-07-09 12:33
浏览 49
已采纳

我无法检索控制器在视图文件中发送的值

I am using codeigniter.When I perform add function I need to calculate tax. I have tax value in a table I need to fetch the value from the table and use it in my view page.

 public function view()
        {
            $this->load->library('session');
            $data['service_detail']=$this->session->userdata('service_detail');
            $data['tax'] = $this->settings_model->get_tax();  
            $data['main_content'] = 'admin/service/view';
            $this->load->view('includes/template', $data); 
        }

In model file I have this function by which I get the tax value from the table

public function get_tax()
{
    $query = $this->db->query("SELECT company_tax13 FROM service_settings ");
    $result = $query->result_array();
    return $result;
}

Here is my view file where i get the tax value.

  <div class="form-group">
    <label for="email">Service price: <?=$service_detail['service_price']?> Rs</label>
    </div>
    <div class="form-group">
    <label for="email">Tax Percentage : <?=$tax['company_tax13']?>%
    <div class="form-group">
    <?php 
     $tax_percentage=$tax['company_tax13'];
    if(strstr($service_detail['service_tax'],"inclusive")==true) {
    $taxamount=$service_detail['service_price']-($service_detail['service_price']/(1+($tax_percentage/100)));
    $grand=$service_detail['service_price'];
    }
    else {
    $taxamount=($service_detail['service_price']*(1+($tax_percentage/100)))-$service_detail['service_price'];
    $grand=$taxamount+$service_detail['service_price'];
    }
    ?>
    <label for="email">Tax Amount : <?php echo $taxamount; ?> Rs</label>
    <div class="form-group">
    <label for="email">Grand Amount : <?php echo $grand; ?> Rs</label>
    </div>

I could not get the tax value in my page. Can someone help me. I do not know the reason why i get no value in my output.

Edit 01

In service_detail['service_price'] contains either inclusive or exclusive. with that value I use strstr() to compare that string.

</div>
  • 写回答

1条回答 默认 最新

  • dongliyan9190 2015-07-09 12:38
    关注

    use row_array() instead of result_array() because result_array() returns the first value in index 0 and you should call:

    $tax[0]['company_tax13'];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数