Attempt to assign property of non-object in...
Posted on
16th Feb 2014 07:03 pm by
admin
I'm having issues with the following function in PHP 5...
function getTreeWithChildren()
{
Did you know?Explore Trending and Topic pages for more stories like this.
$category_id = $this->fields['id'];
$parent_id = $this->fields['parent'];
$this->DB->build( array( 'select' => join(',', $this->getFields()),
'from' => $this->table,
'order' => $this->fields['sort']
) );
$this->DB->execute();
// create a pseudo root level object
$root = new stdClass;
$root->$category_id = 0;
$root->children = array();
$arr = array($root);
// populate array and create empty child array
while ($row = $this->DB->fetch()) {
$arr[$row->$category_id] = $row;
$arr[$row->$category_id]->children = array();
}
// build child data
foreach ($arr as $id => $row) {
if (isset($row->$parent_id))
$arr[$row->$parent_id]->children[$id] = $id;
}
return $arr;
}
I'm getting the error
QuoteAttempt to assign property of non-object in ... on line 391
which is...
$arr[$row->$category_id]->children = array();
I've tried typecasting "$this->DB->fetch()" to an object with...
while ($row = (object) $this->DB->fetch()) {
but get a maximum execution time exceeded error instead.
The code was originally written for PHP 4 so I suspect it might be a way the objects are handled and the use of stdClass()?
I'd be extremely grateful if somebody could give me pointers to make this PHP5 compatible (5.2.9)? Thanks in advance
No comments posted yet
Your Answer:
Login to answer
84
54
Other forums
problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo
HTML Form Server Side Validation
Hi, Im new here, im currently doing a website for a friend, and I have designed using snippets from
How to show next and prev records
Hi all,
Sorry if this is simple, i'm very new to php, well, any programming language actually
md5 is it unique
I know this is most likely one of many simple questions that can be found semi easily. But I'm press
how to validate date using javascript
I need to validate date in textbox using javascript..
The date is must be not greater than TODAY
Structure Question - One Table or One Table Per Record Set?
I have a web app (mySQL and PHP) which allows people to create an item with up to 200 records which
help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu
Form a inline view based on the results of the previous query?
Hi Experts,
Can we form a inline view on the results of a previous query (another inline view)?
Warning: mysql_num_rows() expects parameter 1
When i add quote at the end of this link
example:http://localhost/articlemania/category.php?cid=3
Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is