0
votes

Sending Value from controller to model but it shows error " A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'email'

Filename: models/Pmodel.php

Line Number: 58 "

This is the controller which sends the value

$user_email=$_GET['email'];
$this->load->model('Pmodel');

$data['email']=$this->Pmodel->profile_model($user_email);

$this->load->view('dashboard/profile',$data);

and now the model that acquire the values

public function profile_model($arr)
{
    $email=$arr->'email';

    print_r($email);

    $query=$this->db->where(['user_data.email'=>$email])
        ->from('user')
        ->join('user_data', 'user_data.email = user.email')
        ->get();    


    $q= $query->result_array(); 

    return $q;
}

When i Print_r($email) it shows error

2
first insert an id for joining table - Parvez Ahmed
i am not using 'id'. its email that is common in my table so i have to use email. - Himanshu Goyal
then you can use only one table. - Parvez Ahmed
I got the answer i just have to pass the value since its getting only single value thanx for your help. - Himanshu Goyal

2 Answers

0
votes

$email=$arr->'email'

Maybe replace it with this: $email=$arr['email'] Or $email=$arr->email

0
votes

try to print_r($arr) only.

you can just directly use like this

$query=$this->db->where(['user_data.email'=>$arr]) ->from('user') ->join('user_data', 'user_data.email = user.email') ->get();

Or,

$email = $arr;

$query=$this->db->where(['user_data.email'=>$email]) ->from('user') ->join('user_data', 'user_data.email = user.email') ->get();