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 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败