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
Php - mysql select?
hi, i have this code:
Code: <?php
session_start();
// dBase file
include &quo
how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt ?
how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt and so on 200-300 into file 3.txt ?
mr8m - reverse document
Friends,
I'm trying to reverse a document held by MIRO, but it reports the message balan
Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",
substr(I_NAME, IN
Question about the upload of large files
Hi there,
I have a question about the upload of large files, like videos (files generally abo
dynamic table with forms
I have a table that is populated with mysql data and in teh first column there is a raido button tha
Xml parsing
I need a suggestion about parsing xml with multiply parts like pervious...
i.e. different device
Login script (probably a simple error)
dbConfig.php
Code: <?
// Replace the variable values below
// with your specific dat
Probably a simple error...
I'm getting the error -- Parse error: syntax error, unexpected '{' in /home/content/c/s/t/csteffen24
webpage with (simple) login & mysql-db
Hi all,
What I was looking for before was a multi-user password manager, web-based! The offer