Welcome Guest, Not a member yet? Register   Sign In
Cannot use object of type stdClass as array
#1

Hello,

How to fix this error message?

Can you help?

Fatal error: Cannot use object of type stdClass as array in C:\Program Files\EasyPHP-Devserver-16.1\eds-www\companygiondaci\application\views\pcategories.php on line 56

A PHP Error was encountered
Severity: Error
Message: Cannot use object of type stdClass as array
Filename: views/pcategories.php
Line Number: 56
Backtrace:



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>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            
                            <?
php foreach ($posts as $post): ?>
                            
                            <tr>
                                <td><?php echo $post['ctgparent_name']; ?></td>
                                <td><?php echo $post['ctgparent_description']; ?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg/'.$post->ctgp_no); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" onclick="location.href='<?php echo site_url('cpages/editparentctg/'.$post->ctgp_no); ?>';">DELETE</button></td>    
                            </td>    
                                                                                    
                            <?php endforeach; ?>    
                            
                        </table>            
                        </div>
                    </div>                    
                </div>
            </div> 



controllers/Cpages.php


PHP Code:
public function pcategories() { 
    
            
        
$data['posts'] = $this->Mpages->call_parentctg();

        
//$data['ctgparent_name'] = $this->Mpages->call_parentctg();
        //$data['ctgparent_description'] = "Second";//$this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 



models/Mpages.php


PHP Code:
    public function call_parentctg()
    {
        
        
$query $this->db->get('menu_parent');
        return 
$query->result();
                        
    } 
" If I looks more intelligence please increase my reputation."
Reply
#2

This is at least the third time you have asked this same question, in slightly different contexts.
Reply
#3

He just does not know the difference between an array and a object.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

Everybody raise your hand if you're getting tired of this guy flooding the forum with beginner PHP problems trying to find people to do the coding for him...

*** raising both hands! ***
Reply
#5

The easiest way to fix this error and probably the only way in your case is to hire someone to finish your project.
A good decision is based on knowledge and not on numbers. - Plato

Reply
#6

(This post was last modified: 10-10-2016, 04:01 AM by PaulD.)

(10-10-2016, 02:20 AM)RogerMore Wrote: Everybody raise your hand if you're getting tired of this guy flooding the forum with beginner PHP problems trying to find people to do the coding for him...

*** raising both hands! ***
*** raising both hands too! ***

(10-10-2016, 03:20 AM)salain Wrote: The easiest way to fix this error and probably the only way in your case is to hire someone to finish your project.
LOL - So true and so funny.

It is not that he is a beginner, it is the apparent lack care and attention to the most blindingly obvious things. And a reputation of -30 says quite a lot in itself. One thing I have loved about learning PHP is that it is very easy to learn. The error messages are usually extremely helpful. The language is extremely well documented. CI is the same, extremely easy to learn, exceptional documentation, very good error logging and messaging. Even after years of use I find PHP funtions that amaze me, and CI functionality that is exceptionally useful. We all get stuck on basic things on occasion, but to not read documentation, to not read the php error messages, to not learn why something is wrong instead of just fixing it, to not read the many many online resources available, to not look through the hundreds of examples, to not learn from others, but to keep asking the same things again and again, is just simply frustrating.

For ages I thought he was a troll, just having a laugh. I find his posts quite amusing and do not think he should be banned. I have just stopped responding to them. (Except this one but I am at home, a bit bored, waiting for an Amazon delivery).
Reply
#7

(This post was last modified: 10-10-2016, 06:26 AM by RogerMore.)

Hey PaulD,

There was a time that some of the problems he came up with were funny. Nowadays they mainly irritate me. 

Don't get me wrong, there's nothing wrong with beginners questions. One of the reason's I come to the forum is to help an occasional fellow CI user when I have the time, beginner or not. It's starting to look a little disrespectful to people who try to help others, when it is obvious that this person doesn't have the decency spend a couple of minutes reading error messages or use the search box of the CI user manual or Google for that matter.

Sometimes this guy is in more than 3 or more of the 10 latest threads, while there are other people with real questions who also are trying to get their problems solved... 
I wouldn't mind a new feature added to the forum where I can use the Ignore list to filter this guy's posts out of the posts list...  Big Grin

-Roger
Reply
#8

He probably thinks that a reputation of -30 is a php error also.  Big Grin
Reply
#9

(This post was last modified: 10-11-2016, 03:21 AM by wolfgang1983.)

Because it's an array   Rolleyes Rolleyes   http://www.codeigniter.com/user_guide/da...sults.html


Code:
return $query->result_array();

http://www.codeigniter.com/user_guide/da...sult_array


PHP Code:
<?php foreach ($posts as $post) {?>
   <?php echo $post['test'];?>
<?php 
}?>

If you want to use result then

Code:
return $query->result();

On view some thing like

PHP Code:
<?php foreach ($posts as $post) {?>
   <?php echo $post->test;?>
<?php 
}?>


Fully read manual.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB