• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
class CI_DB_mysqli_result could not be converted to string

#1
Hello,

I am trying to fix this error message but could not find a way out yet.  Can anyone help me out?  Thanks in advance.


A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysqli_result could not be converted to string
Filename: views/pcategories.php
Line Number: 53
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\EcommerceGiondaCI\application\views\pcategories.php
Line: 53
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\EcommerceGiondaCI\application\controllers\Cpages.php
Line: 215
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\EcommerceGiondaCI\index.php
Line: 315
Function: require_once



models/Pages_model.php


PHP Code:
public function call_menu()
        {
                
$this->db->select('*')->from('pages');
        
             
   $query $this->db->get();

                return 
$query->result();        
        } 



controllers/cpages.php


PHP Code:
public function pcategories() {  
    
        $data
['menu'] = $this->db->get('pages');
    
        
$this->load->view('pcategories'$data);  
    
    
    



views/pcategories.php


PHP Code:
<div class="row-fluid">
                <
div class="span12">
                    
                    <
button type="button" class="add" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">ADD PARENT CATEGORIES</button
                    
                    <
div class="widget-box">
                        <
div class="widget-title"><h5>Parent Categories</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            <
tr>
                                <
td><?php echo $menu?></td>
                                <td>Mens</td>
                                <td><button type="button" class="edit" href="adminform.php">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td>Womens</td>
                                <td>Womens</td>
                                <td><button type="button" class="edit" href="adminform.php">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                        </table>            
                        </div>
                    </div>                    
                </div>
            </div> 


Line 53:                              <td><?php echo $menu; ?></td>
" If I looks more intelligence please increase my reputation."
Reply

#2
Do you know the difference between a result() object and a result_array() array?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Its all explained in the ci docs here

Generating Query Results
http://www.codeigniter.com/user_guide/da...sults.html


In

PHP Code:
public function call_menu()
{
    
$this->db->select('*')->from('pages');

    
$query $this->db->get();

    return 
$query->result();




change 

Code:
return $query->result();
to

Code:
return $query->result_array();


This will give you an array to work with as follows from the controller

PHP Code:
public function pcategories()
{
    
$data['menu'] = $this->pages_model->call_menu();

    
$this->load->view('pcategories'$data);




And in your view you can show the results as follows

PHP Code:
foreach ($menu as $array => $row)
{
    
print_r($row);

Reply

#4
He never learns anything he just keeps asking the same error questions over and over.

Sit down and take the time to try and learn what your trying to do.

Google search is your friend.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.