0

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.

3
Contributors
4
Replies
38
Views
3 Years
Discussion Span
Last Post by gabrielcastillo
0

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.

0

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
}
0

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

0

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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.