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

[eluser]Unknown[/eluser]
Model:
Code:
<?php
class Blogm extends CI_Model{

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function get()
    {
        $query = $this->db->get('post', 1);
        return $query->result();
    }
}
?>

View:
Code:
<h2>

&lt;?php
foreach($query as $a):
echo $a;
endforeach;
?&gt;

</h2>
&lt;/body&gt;
&lt;/html&gt;

Controller:
Code:
&lt;?php
class Blog extends CI_Controller{

    public function __construct(){
        parent::__construct();
        $this->load->model('Blogm','',TRUE);
    }
    public function index(){
    
        $data['title'] = 'Sblog';
        $data['message'] = 'My Sblog';
        $data['menu_item'] = array('home','contact');
        
        $this->load->view('headerv.php', $data);
        
        $data['query'] = $this->Blogm->get();
        
        $this->load->view('bodyv.php', $data);
        //$this->load->view('sidebarv.php');
        //$this->load->view('footerv.php');
    }
}
?&gt;

Database:
Code:
id    int(11)            No    None    auto_increment                                  
    title    text
MIME: text/plain    latin1_swedish_ci        No    None                                    
    content    text
MIME: text/plain    latin1_swedish_ci        No    None                                    
    time    timestamp        on update CURRENT_TIMESTAMP    No    CURRENT_TIMESTAMP    on update CURRENT_TIMESTAMP                                  
    posted    int(1)            No    0

Database has only one entry...

Anyone help pls..

This is my error..
Code:
A PHP Error was encountered

Severity: 4096

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

Filename: views/bodyv.php

Line Number: 5
#2

[eluser]marjune[/eluser]
Code:
<h2>

&lt;?php
foreach($query as $a):
echo $a->databasefieldnamehere;
endforeach;
?&gt;

</h2>
&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB