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: 101
the code id

  <?php foreach($query->result() as $rows): ?>
    <?php echo $rows->title; ?>
  <?php endforeach; ?>

Any solution.

Recommended Answers

All 4 Replies

Hi,

can you try reading this? If it fails to solve your problem let us know. The answer you are looking for is located near the bottom of the page.

We would appreciate it, if you can post part of your controller, model, and view files for the above codes. Posting the entire page will just create confusion. Only the methods that are related to your problem.

Try this:

$results = $query->result() // Object
$results = $query->result_array(); //Array

foreach($results as $row){
    echo $row['value']; // array method
    echo $row->value; // Object method
}

this is my controller

<?php

/**
 * controllers/contact.php
 *
 * ------------------------------------------------------------------------
 */
class Blog extends Application {

    function __construct() {
        parent::__construct();
       // $this->load->scaffolding('entries');  // date 3/2/2014
    }

    //-------------------------------------------------------------
    //  The normal pages
    //-------------------------------------------------------------

    function index() {
        $this->data['title'] = 'My Wonderful Webapp';
        $this->data['pagebody'] = 'blog';
        $this->data['query']=$this->db->get('entries'); // 3/2/2014
       //4/2

        //$row = $query->row();
        //$data=array( 'title' =>$row->title,
         //   'body'=> $row->body);
        $this->render();
    }

}

/* End of file contact.php */
/* Location: application/controllers/contact.php */

and this is my view

<?php foreach($query->result_array() as $row): ?>
   <p> <?php echo $row['title']; ?></p>
    <?php echo $row['date1']; ?>
  <?php endforeach; ?>

I am still getting the same error

Are you using Codeigniter? What version?

if so your controller is incorrect. If you are using updated version of codeigniter your controller needs to be.

Controller:

    <?php
    /**
    * controllers/contact.php
    *
    * ------------------------------------------------------------------------
    */
    class Blog extends CI_Controller {

        function __construct() {
            parent::__construct();

        }
        //-------------------------------------------------------------
        // The normal pages
        //-------------------------------------------------------------

        public function index() {

            $this->data['title'] = 'My Wonderful Webapp';
            $this->data['pagebody'] = 'blog';
            $this->data['query']=$this->db->get('entries'); // 3/2/2014

            $this->data['query']->result_array();

            $this->load->view('blog', $this->data);

        }

    }
    /* End of file contact.php */
    /* Location: application/controllers/contact.php */

View:

<html>
<head>
    <title><?php echo $pagebody; ?> · <?php echo $title ?></title>
</head>
<body>

    <?php foreach($query as $result): ?>
    <h1><?php echo $result['title']; ?><span><?php echo $date1; ?></span></h1>
    <p><?php echo $result['body']; ?></p>
    <?php endforeach; ?>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.