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 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳