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

[eluser]Mitja B.[/eluser]
Code:
$data['title'] = ":: BlueTraker :: Home ::";
$data['query'] = $this->db->query("SELECT * FROM news WHERE Status > 0 ORDER BY id DESC LIMIT 4");

and i get

Quote:A PHP Error was encountered

Severity: 4096

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

Filename: libraries/Parser.php

Line Number: 63

What is wrong here?
#2

[eluser]xwero[/eluser]
You can't add the query object as content. You have to use the result method before you pass it on to the table library.
#3

[eluser]Lotus18[/eluser]
[quote author="xwero" date="1223917015"]You can't add the query object as content. You have to use the result method before you pass it on to the table library.[/quote]

What do you mean by result method? I also have same problem with the OP. I read this article but I guess this is wrong or maybe I don't really get it. Please give us some example on how to this or give me some sites regarding this problem.

So far I have this code:
Code:
function comments(){
        //echo 'Testing...';    
        $data['title']="My Comment Title";
        $data['comments']="Member Comments";
        $sqlGetTitle="SELECT title FROM tblblogs WHERE blog_id=".$this->uri->segment(3);
        $row=$sqlGetTitle->row_array();
        $data['heading']=$row['title'];
        $this->db->where('blog_id', $this->uri->segment(3));
        $data['query']=$this->db->get('tblComments');
        $this->load->view('blogs/comments', $data);
    }


Any suggestions will be greatly appreciated Smile

Rey Sean
#4

[eluser]Lotus18[/eluser]
As I woke up early this morning and after a series of trial and error at last I got it Smile
#5

[eluser]Jan_1[/eluser]
Could you please explain how you solved it?
Got the same - Need a hint. Thank you!!!
#6

[eluser]andrewtheandroid[/eluser]
[quote author="Jan from Hamburg" date="1235317167"]Could you please explain how you solved it?
Got the same - Need a hint. Thank you!!![/quote]

I know this is an old post but for anyone else wondering how to solve this..

What the first reply meant was that you can't convert the query object to a result. To do this you need to use the result() or result_array() method in the
Generating Query Results userguide.

Example:
Where you are getting your result (eg. a model)
Code:
function getProfile($staffid) {
        // Perform query
        $query = $this->db->get_where('staff',array('staffid'=>$staffid));
        // Get result can also use result_array()
        return $query->result();
    }

Where you are parsing the results (eg. controller). and sending to view.
Code:
// Obtaining result
$result = $this->Staffmodel->getProfile($staffid);
// You may need to use this to get first result if your (if in doubt use var_dump())
$profile = $result[0];
// Load the parser
$this->load->library('parser');
// Parse contents (in this case set 'TRUE' if you want result in form of string)
$content = $this->parser->parse('templates/profile_tpl',$profile,TRUE);
// Send string to view and load view
$this->load->view('Template',array('content'=>$content));
#7

[eluser]seismic[/eluser]
This is how i make it:
Controller
Code:
<?php
class Test extends Controller {
  function Test() {
    parent::__construct();    
  }      

  function index() {
    parent::Controller();
  }

  function funkcja($arg) {  //$arg is parameter taken from url (for eg. article number)
    $this->load->model('model_test');
    $tablica['zmienna'] = $this->model_test->getDane($arg);
    $this->load->view('szablon_test/widok_index', $tablica);
  }
}
?>

Model:
Code:
<?php
class Model_test extends Model {

  function Model_test() {
    parent::Model();
    $this->load->database();
  }

  function getDane($arg){
  $query = $this->db->query('SELECT content FROM site_pages WHERE id_page='.$arg.';');
  $row = $query->row(); //takes only one result row
  $wartosc = $row->content;
  return $wartosc;
  }
}

View:
Code:
<HTML><head></head>

<body>
<div id="outer">

<div id="left">
<div class="navheader">Main Menu</div>
    <ul>
    <li><a href="&lt;?php echo base_url();?&gt;test/funkcja/7">Article about Software</a></li>
    <li><a href="&lt;?php echo base_url();?&gt;test/funkcja/8">Article about Hardware</a></li>
    </ul>
</div>
</div>

<div id="right">
&lt;?PHP
echo $zmienna;
?&gt;
</div>

</div>

&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB