dpjs2005 2018-02-27 04:27
浏览 44

将数组作为参数传递给PHP CodeIgniter中的模型

I'm trying to pass as Array as parameter to Stored Procedure in my Code-Igniter application. When I'm print that array it gives me correct result of selected values. But it gives me an error in my model function.

Here is my controller:

public function index()
{
        $propertyType=$this->input->post('property_type');
        $area=$this->input->post('area_id');
        $clustersID['cluster']=$this->input->post('cluster_id');
        $stageId=$this->input->post('property_status');
        print_r($clustersID);
        $data['properties'] = $this->p->getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId);

            // echo "<pre>";
            // print_r($data['properties']);
            // echo "</pre>";
            // exit();
            //$data['props'] = $this->p->PropView($propId);
            $this->load->view('template/header', $data);
            $this->load->view('Property/property_view', $data);
            $this->load->view('template/footer');
    }

Here is my Model:

public function getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId)
    {
        $query = $this->db->query("call fetch_propertyType_Area_Cluster_Stage($propertyType,$area,$clustersID,$stageId)");
        if ($query) {
            $data = $query->result();
            $query->next_result(); 
            $query->free_result();
            return $data;
        }else{
            return false;
        }
    }

Error:

A PHP Error was encountered Severity: Notice

Message: Array to string conversion

Filename: models/Property_m.php

Line Number: 26

Backtrace:

File: /opt/lampp/htdocs/livemg/application/models/Property_m.php Line: 26 Function: _error_handler

File: /opt/lampp/htdocs/livemg/application/controllers/Property.php Line: 61 Function: getPropertyByAreaCluster

File: /opt/lampp/htdocs/livemg/index.php Line: 315 Function: require_once

A Database Error Occurred Error Number: 1054

Unknown column 'Array' in 'field list'

call fetch_propertyType_Area_Cluster_Stage(0,0,Array,0)

Filename: models/Property_m.php

Line Number: 26

  • 写回答

2条回答 默认 最新

  • dqmhgz5848 2018-02-27 05:10
    关注

    I got an answer, just convert that array to string and pass it.

        public function index()
        {
            $propertyType=$this->input->post('property_type');
            $area=$this->input->post('area_id');
            $clustersID['cluster']=$this->input->post('cluster_id');
            $clusterString = implode(',', $clustersID['cluster']);
    
            echo "<pre>";
            // var_dump($clustersID['cluster']);
            echo $clusterString;
            echo "</pre>";
            $stageId=$this->input->post('property_status');
            print_r($clustersID);
            $data['properties'] = $this->p->getPropertyByAreaCluster($propertyType, $area, $clustersID, $stageId);
    
            //$data['props'] = $this->p->PropView($propId);
            $this->load->view('template/header', $data);
            $this->load->view('Property/property_view', $data);
            $this->load->view('template/footer');
       }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题