[nycphp-talk] Managing Nested Sets in a Database
cliff
cliff at pinestream.com
Wed Nov 9 13:44:12 EST 2005
I wrote an ugly class that I've used for product categories and nested FAQs.
DB structure is: id, parent id, lft, rgt, level, stuff.
Haven't fully exercised it and Chris' point regarding InnoDB and tree moves
is eye-opening. Here's the jist of it. If you want the guts, yell.
class DoFaq
public function GetFaqs()
public function GetFaq($faqId)
public function Add($question, $answer)
public function Update($faqId, $question, $answer)
public function Delete($faqId)
public function AddSub($parentId, $question, $answer)
public function Promote($faqId)
public function Demote($faqId)
public function MoveUpDown($faqId, $updwn)
public function GetPath($faqId)
private function GetById($faqId)
private function GetByLft($lft)
private function GetByRgt($rgt)
private function GetTree($lft, $rgt)
private function UpdateTree($faq)
private function Move($lft, $rgt, $space, $updwn)
private function AddSpace($lrnum, $space)
}//end class
?>
Cliff Hirsch
--
Pinestream Communications, Inc.
www.pinestream.com
On Wed, 9 Nov 2005 13:20:56 -0500, csnyder wrote
> On 11/9/05, Jeff Loiselle <jeff.loiselle at gmail.com> wrote:
> > From: The Feeling Quite Lazy Today Department...
> >
> > Anyone know of any existing PHP/MySQL code with which one can manage
> > nested sets in a database. Anyone have a category manager they want to
> > share? ;-) If not, I'll post one when I'm done. ;-)
> >
>
> Hans will probably post a newer version (if one exists...) but
> pnsm.pcom is one of the first open source implementations of nested
> sets in MySQL+PHP:
> http://cvs.nyphp.org/cvsweb.cgi/clew/lib/pnsm.pcom?rev=1.1&content-
> type=text/x-cvsweb-markup
>
> Unfortunately that earlyish version has no "move" method...
>
> I'm supposed to publish a much more recent implementation that I've
> been working with, but I haven't had time to put the site together.
> Hmmm, a preview can be found here:
> http://pine.fcny.org/~csnyder/fcnyNode.txt
>
> --
> Chris Snyder
> http://chxo.com/
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
More information about the talk
mailing list