> Good news and bad news:
>
> I presumably found a way:
>
> <?php
>
> require("./dbconnect.inc.php");
>
> function rebuild_tree($parent_id, $left)
> {
> global $dbh;
>
> // the right value of this node is the left value + 1
> $right = $left+1;
>
> // get all children of this node
> $stmt = $dbh -> prepare("SELECT id,keyword FROM keywords WHERE
> parent_id='" . $parent . "' AND approved = 1");
> $stmt -> execute();
> while ($row = $stmt -> fetch(PDO::FETCH_ASSOC))
> {
> $right = rebuild_tree($row['id'], $right);
> }
>
> // we've got the left value, and now that we've processed
> // the children of this node we also know the right value
> echo('UPDATE categories SET lft='.$left.', rght='.
> $right.' WHERE id="'.$parent_id.'";' . "\n");
>
> // return the right value of this node + 1
> return $right+1;
> }
>
> rebuild_tree('0',1);
>
> ?>
>
> Bad news : my server doesn't want to do it due to memory issues:
>
> Fatal error: Out of memory (allocated 5505024) (tried to allocate 40
> bytes) in /customers/nonimportante.es/nonimportante.es/httpd.www/mptt/
> build_lr_query.php on line 14
>
> Any suggestions?
>
> thx + greetz,
> Marv
>
> On Sep 24, 7:45 pm, cricket <zijn.digi...@gmail.com> wrote:
>
>
>
> > On Fri, Sep 24, 2010 at 11:49 AM, marvelade <marvel...@gmail.com> wrote:
>
> > > I suppose I need to add 'lft' and 'rght' fields to my database but how
> > > do I calculate these values? I never heard of MPTT before and I think
> > > I understand the basics after reading an article about it (http://
> > > articles.sitepoint.com/article/hierarchical-data-database/2), but I
> > > can't really think of an algorythm that would update an existing
> > > database table when only the parent info is available...
>
> > > Any pointers?
I'd recommend looking at the book and api for the tree behavior,
before embarking on a needless quest. This one liner controller
snippet does what you're trying to do:
$this->MyTreeModel->recover();
AD
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment