1

Hello i need help i am trying to pass three different variables from the controller of a codeigniter to model so i created an array and pass it then i exploded and i am getting the error explode() expects parameter 2 to be string, array given

The controller

 $data = array(
                'district_id' => $this->input->post('district') ,
                'limit' => $limit,
                'offset' => $offset,

            );


   $data['tubadili'] = $this->wapi_db->search_bar($data);

The Model function

public function search_bar($data){

    $dataArray = explode(',' , $data);

    $district_id = $dataArray[0];

    $limit = $dataArray[1];

    $offset = $dataArray[2];

    $this->db->select('entertainment.Name,entertainment.ID,entertainment.Category,entertainment.Location,entertainment.Description,
                       image.ImagePath,image.Enter_ID,entertainment.DistrictID');

    $this->db->from('entertainment');

    $this->db->join('image', 'image.Enter_ID=entertainment.ID');

     $this->db->where('entertainment.Category',"Bar");

     $this->db->where('entertainment.DistrictID', $district_id);


    $this->db->limit($limit, $offset);

    $query = $this->db->get();

    return $query->result();








}

1 Answer 1

0

Change:

$dataArray = explode(',' , $data);
$district_id = $dataArray[0];
$limit = $dataArray[1];
$offset = $dataArray[2];

To:

extract($data);

Basically what this does is take the associative array you have in $data and extracts them into their own variables, which is logically equal to:

$district_id = $data['district_id'];
$limit = $data['limit'];
$offset = $data['offset'];

Your issue is that you were trying to explode $data which will not work, explode works on strings and not arrays.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello Thank you Very Much It is working Perfectly Gracies @Aziz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.