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 once tackled that very problem but wasn't successful. I still think
> it must be possible to write a script to do it but, in the end, I just
> created a text file and totted through it "by hand". I did search
> online and, I believe, posted a query to this list, but couldn't find
> anything.
>
> > Can I use the CakePHP tree functionality with just the parent_id info
> > (I'd guess not?) ?
>
> I'm not sure. I suspect not. It seems to me, though, that MPTT would
> be the way to go for what you're doing.
>
> BTW, do check out this article:http://bakery.cakephp.org/articles/view/tree-helper-1
>
> It's a little bit confusing but it's definitely useful. I think it'd
> suit your situation. Let me know if you need some pointers.
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