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
Save data in input fields when they press "BACK BUTTON"
Hi, this is html form: And let's say they get a error "Please enter ur title must be more then
Having problemswith multithreading and prime numbers
I have an assignment when I'm suppose to do the following:
Write a multithreaded Java, Pt
Help, Base64 encoding url and decoding server side.
Hello everyone, i have a website with videos and games and also provide an embed code which people c
Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is
Contact Form Not Working When I Add Validation Codes
So I built my first working PHP "Contact Us" like form. But, I have been trying to now mak
pagination numbering pattern
Hello,
I have following code which works great for pagination. but i have small issue now.
Include ("Absolute Path") of a file?
I'm not sure what I'm doing wrong. I am writing my php code in the same directory of the file that
Header redirect
Hello ive got a problem ive got form with its action set to itself.
Code: <form id="f
max() problem
I have a while loop to get image names.
Code: $imagequery = mysql_query("SELECT * FROM ad_i
Trouble verifying database password
Thankyou to everyone who responded to my last post (I can't find the posting, it has been buried). <