Getting Error When passing value from controller to model in codeigniter - php

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

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();

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

Related

cant display the data from controller

My problem is that I can't get data in database but if I use var_dump() I have data. This is the error:
A PHP Error was encountered Severity: Notice Message: Undefined index: projectid Filename: views/accounting_status.php Line Number: 46
This is my View
This page was accesed incorrectly.
<div class="well">
<p><h1><?=$p['projectid']?></h1></p>
<p><?=$p['code']?></p></div>
This is my Controller
function id($projectid){
$data['p'] = $this->Accounting_Model->get_awardedid($projectid);
//echo "<pre>".print_r($data)."</pre>";
$this->load->view('tmp_header');
$this->load->view('accounting_status',$data);
}
This is my Model
function get_awardedid($projectid){
$this->db->select('*')->from('projects')
->join('customer', 'projects.customerid = customer.customerid')
->join('employees', 'projects.endorse_by = employees.employeeid')
->where(array('acctg'=>1,'projectid'=>$projectid))
->order_by('datecreated', 'desc');
$query = $this->db->get();
return $query->result_array();
}
If the result will be a single row then change on model as follows:
function get_awardedid($projectid){
$this->db->select('*')->from('projects')
->join('customer', 'projects.customerid = customer.customerid')
->join('employees', 'projects.endorse_by = employees.employeeid')
->where(array('acctg'=>1,'projectid'=>$projectid))
->order_by('datecreated', 'desc');
$query = $this->db->get();
return $query->row_array();
}
If result is multiple records, then use for loop to print the values in view.
<div class="well">foreach($p as $value){<p><h1><?=$value['projectid']?></h1></p><p><?=$value['code']?></p>}</div>

Undefined property: stdClass in my codeigniter controller

This is my controller function
public function check_orgn_mail()
{
$this->load->model('registrationmodel', '', TRUE);
$omail = $this->input->post('mailid');
$mailresult = $this->registrationmodel->check_org_mail();
$smil = explode("#", $omail);
$registerCompanyID = null;
if ($mailresult)
{
foreach ($mailresult as $row)
{
$registerCompanyID = $row->id;
$cmail = explode("#", $row->email);
$acmail[] = $cmail[1];
}
if (in_array($smil[1], $acmail))
{
return TRUE;
}
}
$this->form_validation->set_message('check_orgn_mail', 'Invalid Organization Mail id.');
return false;
}
This is the function in my model
function check_org_mail()
{
$this->db->select('email','id');
$this->db->from('customers');
$this->db->where('status', 1);
$query_emai = $this->db->get();
return $query_emai->result();
}
I am getting this error
Severity: Notice
Message: Undefined property: stdClass::$id Filename:
controllers/registration.php
I tried some trial and error but not working. Please help me with this. Previously it was working fine but when I checked with the different mail id, it started giving this error.
change your select to this:
$this->db->select('email, id');
You need to use
$this->db->select('email, id');
All columns are supposed be a single string argument separated by commas.
You are providing multiple arguments.

PHP CodeIgniter: Trying to get property of non-object

Everything seems to work just fine but I keep getting the following error:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/ordermodel.php
Line Number: 24
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/ordermodel.php
Line Number: 31
================================================================
In the view i just echo $company_name
Controller:
$city = $this->ordermodel->get_city($order_reference);
$customerCompanyName = $this->ordermodel->get_company_name($order_reference);
$data['company_name'] = $customerCompanyName;
Model:
function get_city($ordernumber) {
$this->db->where('order_number', $ordernumber);
$city = $this->db->get('order');
return $city->row()->city;
}
function get_company_name($ordernumber) {
$this->db->where('order_number', $ordernumber);
$companyname = $this->db->get('order');
return $companyname->row()->company_name;
}
Use therresult() method, it should elimiate all of your errors
$row = $city->result(); return $row->city;
Seem that your query has no results, try:
function get_company_name($ordernumber) {
$this->db->where('order_number', $ordernumber);
$companyname = $this->db->get('order');
if ($companyname->num_rows() > 0) {
return $companyname->row()->company_name;
}
else {
return '';
}
}

php returning undefined property

In other of not be repetitive, I wrote that getName function to do the duty job for me: the classes querying the database would only send the SQL query:
public function getVolumeServer($id)
{
$str = "SELECT *FROM site_volume_server WHERE site_id='$id'";
return $this->getName($str);
}
public function getName($str)
{
$data = array();
$query = $this->getQuery($str);
if($query){
foreach($query->result() as $row){
array_push($data, $row->name);
}
}
return $data;
}
public function getQuery($str){
$data = array();
$query = $this->db->query($str);
if(!$query || $query->num_rows() == 0){
return false;
}
return $query;
}
However, I'm getting the following error:
<p>Severity: Notice</p>
<p>Message: Undefined property: stdClass::$name</p>
<p>Filename: models/sitematrix_model.php</p>
<p>Line Number: 129</p>
Line 129 is $this->getName($str).
I did not have that before, when that portion of code was embedded in the function, but there are similar functions that only differ by the table being accessed.
Any Thoughts?
Thanks
I am having the same problem except I am trying to access the $agenda->time_from property from __get() which is a time column in agenda table which is retrieved from db properly (I checked the var_dump, ran the query manually in phpMyAdmin).
I do that because the default call parent::_get() won't return the value; it returns NULL instead.
I found a workaround for my problem. All you need to do is to access the value like :
$agenda->_object['time_from']
I guess this is not quite the right solution, but working one.

Trying to add to an array

I'm trying to pass along the question AND the id of the question in the first query and then with that id get that poll's options and add those to the array. Not seeing what I'm doing wronge here.
Here's the error I am getting:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_DB_mysql_result::$row
Filename: models/sitemodel.php
Line Number: 161
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/sitemodel.php
Line Number: 161
Code:
function getPoll() {
$this->db->select('site_polls.id, site_polls_questions.poll_question');
$this->db->from('site_polls');
$this->db->join('site_polls_questions', 'site_polls_questions.id = site_polls.site_polls_questions_id');
$this->db->where('site_polls.status_id', 1);
$this->db->order_by('site_polls.date_posted', 'desc');
$this->db->limit(1);
$query = $this->db->get();
$id = $query->row->id;
$this->db->select('site_polls_questions_options.poll_option');
$this->db->from('site_polls_questions_options');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result_array();
}
I'm trying to figure out how I can add the question of the poll into the array.
row() is a function and not a property.
$id = $query->row()->id;
or
$id = $query->row(0)->id;
$id = $query->row->id;
Should be:
$id = $query->row()->id;
$query->row() is a function, not a property.
Try this:
$query = $this->db->get()->first_row();
if ( !empty($query->id))
{
$id = $query->id;
}
else
{
return array();
}

Categories