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

[eluser]ademar[/eluser]
Hello Guys,

Im new with CI and i got little problem here. I've read the posts with the same error msg but i couldn't figure out whats the problem.


CODE:

Controller:

function index(){

$this->load->model('test_model');

$data['test'] = $this->test_model->get_all();

$this->table->set_heading('Id', 'Desc');

echo $this->table->generate($data);
}

Model:

function get_all(){

$query = $this->db->query("select * from test");

return $query;
}

And i get this error:
Severity: 4096

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

Filename: libraries/Table.php

Line Number: 269


So i've read some questions if you should or not use return $query or returno $query->result() but if i try with ->result() i get this other error:

A PHP Error was encountered

Severity: 4096

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

Filename: libraries/Table.php

Line Number: 269


So, does anyone see what i've forgotten ? I've tried to read other posts but got unlucky.

Thanks,

D
#2

[eluser]Byrro[/eluser]
How are you loading your database?
#3

[eluser]InsiteFX[/eluser]
Code:
function get_all()
{
    $data = array();

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

    if ($query->num_rows() > 0)
    {
        foreach ($query->result_array() as $row)
        {
            $data[] = $row;
        }
    }

    $query->free_result();
    return $data;
}

InsiteFX
#4

[eluser]ademar[/eluser]
[quote author="Byrro" date="1282806551"]How are you loading your database?[/quote]

Yes, if i put my old code, with me creating the table my self with foreach() works fine.
Im loading in config/autoload.php.

$autoload['libraries'] = array('database',...

Thanks anyways man, any other thoughts ?

D
#5

[eluser]ademar[/eluser]
Hello Insite,

Thanks man, but now i got something less explainable:

my returned result when i use your peace of code:

Id Desc
Array Array Array Array

Any helps help, thanks man.

D

[quote author="InsiteFX" date="1282806601"]
Code:
function get_all()
{
    $data = array();

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

    if ($query->num_rows() > 0)
    {
        foreach ($query->result_array() as $row)
        {
            $data[] = $row;
        }
    }

    $query->free_result();
    return $data;
}

InsiteFX[/quote]
#6

[eluser]ademar[/eluser]
Hey Guys,

I wonder something here:

Is that table library used for professional projects? or usually developers prefer to use the classic way to create a table?

Its my first project using CI and we are trying to create a pattern to use here in the company. If the table library is not that used for most of the developers, I'll get it out of our pattern and move forwards in the developing process.

Thanks for all the help received till now.

D




Theme © iAndrew 2016 - Forum software by © MyBB