Welcome Guest, Not a member yet? Register   Sign In
Object of class CI_DB_mysql_result could not be converted to string
#1

[eluser]Craig Ward[/eluser]
Hi,

I am getting the following error and I am not sure how to solve it

------------
A PHP Error was encountered

Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: models/ManageProperty_model.php

Line Number: 21
------------

the model is

------------
<?php

class ManageProperty_model extends Model
{

function get_property_details($p_id, &$b_id)
{
$this->db->where('ID', $p_id);
$q = $this->db->get('properties');
$b_id = $this->db->query('SELECT BRANCH_ID FROM properties WHERE ID = "$p_id"');

if($q->num_rows() >0)
{
foreach ($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}

function get_property_images($p_id)
{
$this->db->where('property_id', $p_id);
$q = $this->db->get('media_image');

if($q->num_rows() >0)
{
foreach ($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}

}
#2

[eluser]steelaz[/eluser]
So where is the line 21?

And what is the purpose of this line?
Code:
$b_id = $this->db->query('SELECT BRANCH_ID FROM properties WHERE ID = "$p_id"');
#3

[eluser]Craig Ward[/eluser]
$b_id is what I am trying to get and pass back to the controller, that line is the one throwing the error
#4

[eluser]mddd[/eluser]
You are passing &$b_id to the function by reference. If you defined $b_id in your controller to be a string, then PHP will have to try and convert your query result object ($this->db->query) into a string. It can't do that and therefore throws an error.

Solution: don't pass $b_id to the function in the first place. Why are you doing that anyway?

Also you are doing two queries to try and achieve the same thing?? It is a bit messy. If all you want is to get the details for id = $p_id, just do:
Code:
function get property_id ($p_id)
{
$this->db->where('id', $p_id);
$q = $this->db->get('properties');
if ($q->num_rows() != 1) return false;
return $q->row();
}
#5

[eluser]steelaz[/eluser]
What mddd said. Using his example, if you want to get BRANCH_ID:

Code:
$property = $this->manageproperty_model->get_property_details($p_id);

$branch_id = $property->BRANCH_ID;




Theme © iAndrew 2016 - Forum software by © MyBB