dongrong8972 2013-05-19 04:44
浏览 40
已采纳

为什么我在CodeIgniter中遇到“数组到字符串转换”错误? [关闭]

I'm currently having a problem with this error:

array to string conversion

Here's the code:

controller:

function get_tariff()
{      
   $this->load->model('model_tariff');
   $data['destination']=$this->input->post('dest',true);
   $data['lines']=$this->input->post('lines',true);
   $data['weight']=$this->input->post('weight',true);
   $data['priceperkg']=$this->model_tariff->get_tariff();
   $data['pricetotal']=$data['priceperkg']* $data['weight'];
   $this->load->view('tariff_result',$data);
}

model:

function get_tariff()
{        
   $destination=$this->input->post('dest');
   $lines=$this->input->post('lines');
   $weightt=$this->input->post('weight');
   $this->db->select('price');
   $this->db->from('view_tariff');
   $this->db->where('city_name',$destination);
   $this->db->where('lines',$lines);
   $price=$this->db->get();
   return $price->result();    
}

view:

Price per kg <?php echo $priceperkg?>;
Bayar total <?php echo $pricetotall?>;
  • 写回答

2条回答 默认 最新

  • doubi7306 2013-05-19 04:56
    关注

    The CodeIgniter database method result() returns an array of objects, not a string literal (price). You need to do some further transformations. For example, if you are expecting a single row, then try row() which returns a single object. In turn, you can then reference the property price:

    return $price->row()->price;
    

    Or, you can treat this several other ways.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?