Location: PHPKode > scripts > Nested Nodes Class > nested-nodes-class/Manual.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Nested Nodes Class Manual</title>
<style>
body{background-color:#FFFFFF}
.code_div
{
border-style:dashed;
border-width:1px;
border-color:#333333;
background-color:#FFE1F0;
position:static;
text-align:left;
width:auto;
font-size:11px;
font-family:Geneva, Arial, Helvetica, sans-serif;
padding:5px;
}
.variable
{
color:#0000bb;
}
.normal
{
color:#333333;
font-size:12px;
}
.big_title
{
font-size:24px;
color:#FF0000;
font-weight:bold;
}
.medium_title
{
font-size:16px;
color:#003300;
font-weight:bold;
}
.normal_title
{
font-size:14px;
color:#FF3300;
font-weight:bold;
}
.style1 {font-size: 12px}
.style2 {font-weight:bold; font-size: 16px;}
</style>
</head>

<body style="font-family:Tahoma">

  <p align="center"><strong class="big_title">NestedNodes Class Manual</strong><font color="#FF9900" size="1"> By Shadi Ali</font></p>
  <p align="left" class="medium_title"><font color="#006600" size="5">Preface:</font><em><br />
  <br />
  Finally the Best Class for Nesting any MySQL table records is HERE!!</em> <br />
      <br />
    Nesting any MySQL table records to be parents and childrens  was never that easy!<br />
      <br />
      Why would you use this class?</p>
  <ul>
    <li>Works on any existing MySQL table! and need only three essential fields (id , position , ord)!!</li>
    <li>Doesn't rely on another classes/objects ... just pure PHP code.</li>
    <li>Support for add/update/delete(childrens too) of the nodes. </li>
    <li>Included the <font color="#0000FF">html_output()</font> method to print a <strong><font color="#FF0000">S</font></strong><font color="#FF0000"><strong>tandard nested Unobtursive list</strong></font>!! <font size="1">( ie: &lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt; )</font></li>
    <li>Included the <font color="#0000FF">html_row_output()</font> method to print a You&gt;Are&gt;Here like menu!! </li>
    <li>Templates for the 2 of the above methods. </li>
    <li>Support for re-ordering nodes inside its level.</li>
    <li>Easy commented code.</li>
    <li>Extremely Easy to extend by just using the $this-&gt;fetch() and $this-&gt;get_position() functions you could do many operations on the nodes.</li>
    <li>Licensed Under BSD means you can use this class for your commercial applications. </li>
    <li>many other benefits .. just continue reading and check it in action in <a href="nodes_test.php">nodes_test.php</a> </li>
    <li>Built on the  Position Chain Idea??</li>
  </ul>
  <p>What is Position Chain Idea..? </p>
  <p>before writing this class, providing a solution  for a nested nodes was done with two popular ways, one of them is to define a database field to carry the parent node id .. and the other way was using SQL Joins.<br />
  with all respect to both ways, I didn't find it easy to deal with the rows after applying one of the ways so thats why i thought in the Position Chain Idea.<br />
    <br />
    in the Position Chain , I store the node family tree/chain in the field called <strong>position</strong> .. the tree start from the first father ID till the node itself ID .. the IDs are separated with right Arrow &gt;<br />
    look at this <br />
    <strong>1&gt;3&gt;5&gt;88&gt;</strong><br />
    from the first look you are able to determine that this row is in the 4th level, and his parent ID is 5 ...  till the first father which have the ID 1.<br />
    <br />
    <em><strong>ok, is the only benefit from such idea to make it easy to read the node family tree when looking to records ..??</strong></em><br />
  Ofcourse this is a great benefit, but its not the only benefit .. this Position Chain facilate the manipulation of the records!<br />
  to get a the family tree just use <font color="#FF3300" size="2">explode(&quot;&gt;&quot;, &quot;1&gt;3&gt;5&gt;88&gt;&quot;)</font> to have the family into array .. print it as you want!!<br />
</p>
  <div class="code_div">
    <p>&lt;?php<br />
    $nodes = new nodes('categories');<br />  
    <br />
    $positionChain = &quot;1&gt;3&gt;5&gt;88&quot;; // i'm just wrtiting any example position<br />
    <br />
    $positions = explode(&quot;&gt;&quot; 
  , $positionChain);<br />
  array_pop($positions); // just remove the last free element.<br />
  <br />
  foreach($positions as $id){<br />
  $category = $nodes-&gt;fetch($id);  <br />
    print_r($category);<br />
    }</p>
?&gt;</div>
  <p><strong><em>ok any other benefit than exploding the position to know the family till the roots ??</em></strong><br />
    sure, what about getting the node depth level from just counting the exploded array!!<br />
  </p>
  <div class="code_div">
    <p>&lt;?php<br />
    <br />
      $positionChain = &quot;1&gt;3&gt;5&gt;88&quot;; // i'm just wrtiting any example position<br />
      <br />
      $positions = explode(&quot;&gt;&quot; 
      , $positionChain);<br />
      $depth = count($positions) -1; // just remove the last free element.<br />
      echo &quot;i'm the node with the id 88 and in the &quot;.$depth&quot;th level!&quot;;
      <br />
      <br />
    ?&gt;</p>
  </div>
  <p>ok enough explaining the idea, you will touch the benefits yourself when you start to write the first line of your codes using the NestedNodes class!<br />
      <br />
      <font color="#FF0000">before reading this manual you may want to check the class in action .. just put the file called <a href="nodes_test.php">node_test.php</a> with the nodes.class.php into a directory on a running webserver ... <em><strong><a href="#categories">execute our categories table query</a></strong></em> , modify the mysql connection values in the first lines of <a href="nodes_test.php">nodes_test.php</a> file .. call it from your browser (ie. http://localhost/nodes/nodes_test.php ) .. and here you go! </font><br />
    <br />
    <strong><font color="#006600" size="5">Manual Start</font></strong>    <br />
    <br />
  MySQL Table:</p>
  <p align="left" class="normal"><font color="#000000" size="2">This class runs on any table which have <strong>only three essential  columns </strong><br />
    ( id =&gt; primary key usually bigint)<br />
    ( position =&gt; holds the position chain .. usually varchar(255) to hold about 50 nested levels). <br />
    ( ord =&gt; holds the items display order in its level )<br /> 
  <br />
The essential table. </font></p>
  <div class="code_div">
    <p>CREATE TABLE `nodes` (<br />
      `id` BIGINT NOT NULL AUTO_INCREMENT ,<br />
      `position` VARCHAR( 255 ) NOT NULL ,<br />
      `ord` int NOT NULL ,</p>
    <p>-- add your fields here<br />
      --  ie -&gt; `node_name` varchar(160),<br />
      -- add your fields here</p>
    <p>PRIMARY KEY ( `id` ) ,<br />
      INDEX ( `position` ) <br />
      );</p>
  </div>

  <p>lets take an example of an articles table:<br />
</p>
  <div class="code_div">
    <p>CREATE TABLE `articles` (<br />
      `id` BIGINT NOT NULL AUTO_INCREMENT ,<br />
      `position` VARCHAR( 255 ) NOT NULL ,<br />
    `ord` int NOT NULL ,<br />
    <br />
    `article_title`   VARCHAR( 255 ) NOT NULL,<br />
    `article_text` text, </p>
    <p>PRIMARY KEY ( `id` ) ,<br />
      INDEX ( `position` ) <br />
      );</p>
</div>
  <p><a name=categories></a>and our working example table , the categories table :-)<br />
    <br />
</p>
  <div class="code_div">
    <p>CREATE TABLE `categories` (<br />
      `id` BIGINT NOT NULL AUTO_INCREMENT ,<br />
      `position` VARCHAR( 255 ) NOT NULL ,<br />
      `ord` int NOT NULL ,<br />
      <br />
      `c_name`   VARCHAR( 255 ) NOT NULL,<br />
      `c_desc` tinytext, </p>
    <p>PRIMARY KEY ( `id` ) ,<br />
      INDEX ( `position` ) <br />
      );</p>
  </div>
  <br />
  don't forget to execute the categories table query as is, so you could test the class out on <a href="nodes_test.php">nodes_test.php</a> <br />
  <hr />
<p class="medium_title">Class Variables:</p>
<p class="normal">Here I'm going to explain the class variables</p>
 <p class="variable"><br />
   <font color="#0000bb" class="variable">$table_name</font> <br />
   <br />
   <span class="normal">this is the MySQL table name which you want the class to work on.<br />
   usage:</span><font color="#FF3300"><span class="style1"><br />
   &lt;? $nodes-&gt;table_name = 'categories' ?&gt;</span></font><span class="normal"> <br />
   to intialize the table name ,<br /> 
   or simply enter the table name when initializing the class <br />
   </span><span class="style1"><font color="#FF3300">&lt;? $nodes= new nodes('categories') ?&gt;</font> </span><br />
   <br />
 $HtmlTree</p>
 <p class="normal">This variable holds the default HTML template for the HTML list, It is used only when you call the<font color="#0000FF"> html_output($id, $clickable=false)</font> method ... its an array and contains 12 elements required to build the nested html list<br />
   <br />
 modify the template value as you want , but always remmeber to put your columns between square brackets [] ( ie. &lt;a href=&quot;?id=<strong>[id]</strong>&quot;&gt;<strong>[article_name]</strong>&lt;/a&gt; ) <strong>[article_name]</strong> will be replaced with the actual article name from your database, same goes on <strong>[id]</strong>. </p>
 <p class="normal_title">default value for the $HtmlTree Variable:</p>

 <div class="code_div"><font color="#0000bb">$nodes</font><font color="#007700">-&gt;</font><font color="#0000bb">HtmlTree&nbsp;</font><font color="#007700">=&nbsp;array( <br />
 </font><font color="#dd0000">&quot;OpenTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;ul&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;the&nbsp;overall&nbsp;tag&nbsp;opener&nbsp;,&nbsp;example&nbsp;&lt;ul&gt; <br />
 </font><font color="#dd0000">&quot;FirstLevelOpenTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;[id]&lt;/a&gt;&lt;ul&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;printed&nbsp;for&nbsp;the&nbsp;ROOT&nbsp;parent&nbsp;(&nbsp;node&nbsp;has&nbsp;children/sub-nodes)&nbsp;ie&nbsp;:&nbsp;&lt;ul&gt;&lt;li&gt;&lt;h2&gt;[name]&lt;/h2&gt; <br />
 </font><font color="#dd0000">&quot;FirstLevelOpenTagSelected&quot;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;&lt;b&gt;[id]&lt;/b&gt;&lt;/a&gt;&lt;ul&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;printed&nbsp;for&nbsp;the&nbsp;ROOT&nbsp;parent&nbsp;(&nbsp;node&nbsp;has&nbsp;children/sub-nodes)&nbsp;ie&nbsp;:&nbsp;&lt;ul&gt;&lt;li&gt;&lt;h2&gt;[name]&lt;/h2&gt; <br />
 </font><font color="#dd0000">&quot;LevelOpenTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;[id]&lt;/a&gt;&lt;ul&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;printed&nbsp;for&nbsp;the&nbsp;parent&nbsp;(&nbsp;node&nbsp;has&nbsp;children/sub-nodes)&nbsp;ie&nbsp;:&nbsp;&lt;ul&gt;&lt;li&gt;&lt;h2&gt;[name]&lt;/h2&gt; <br />
 </font><font color="#dd0000">&quot;LevelOpenTagSelected&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;&lt;b&gt;[id]&lt;/b&gt;&lt;/a&gt;&lt;ul&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;//&nbsp;this&nbsp;is&nbsp;printed&nbsp;for&nbsp;the&nbsp;parent&nbsp;(&nbsp;node&nbsp;has&nbsp;children/sub-nodes)&nbsp;..&nbsp;WHEN&nbsp;SELECTED!&nbsp;ie&nbsp;:&nbsp;&lt;ul&gt;&lt;li&gt;&lt;h2&gt;&lt;STRONG&gt;[name]&lt;/STRONG&gt;&lt;/h2&gt;&nbsp; <br />
 </font><font color="#dd0000">&quot;Node&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;[id]&lt;/a&gt;&lt;/li&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;node&nbsp;item&nbsp;tag&nbsp;..&nbsp; <br />
 </font><font color="#dd0000">&quot;NodeSelected&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;li&gt;&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;&lt;b&gt;[id]&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;node&nbsp;item&nbsp;tag&nbsp;..&nbsp;when&nbsp;selected&nbsp;! <br />
 </font><font color="#dd0000">&quot;FirstLevelCloseTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/ul&gt;&lt;/li&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;ROOT&nbsp;parent&nbsp;tag&nbsp;closer.&nbsp;(&nbsp;when&nbsp;getting&nbsp;out&nbsp;of&nbsp;sub-level) <br />
 </font><font color="#dd0000">&quot;FirstLevelCloseTagSelected&quot;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/ul&gt;&lt;/li&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;ROOT&nbsp;parent&nbsp;tag&nbsp;closer,&nbsp;while&nbsp;selected. <br />
 </font><font color="#dd0000">&quot;LevelCloseTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/ul&gt;&lt;/li&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;parent&nbsp;tag&nbsp;closer.&nbsp;(&nbsp;when&nbsp;getting&nbsp;out&nbsp;of&nbsp;sub-level) <br />
 </font><font color="#dd0000">&quot;LevelCloseTagSelected&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/ul&gt;&lt;/li&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;parent&nbsp;tag&nbsp;closer,&nbsp;while&nbsp;selected. <br />
 </font><font color="#dd0000">&quot;CloseTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/ul&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;the&nbsp;overall&nbsp;tag&nbsp;opener&nbsp;,&nbsp;example&nbsp;&lt;ul&gt; <br />
 </font><font color="#007700">); <br />
</font></div>
 <p><u>look at the following example menu figure to understand how the template is parsed by the class <font color="#0000FF">html_output()</font> method.</u><br />
   <br />
<img  width="722" height="400" src="htmltree.gif" /><br />
<br />
<br />
</p>
 <p class="variable">$HtmlRow</p>
 <p class="normal">The previous HtmlTree variable was about printing standard nesed Unobtursive &lt;ul&gt; menu... Ok .another kind of a popular type of menu but it doesn't follow a standard is the row menu, You&gt;Are&gt;Here like menus ( i.e Home &gt; Programming &gt;PHP ) , this method isn't forgotten in this class.<br />
   <br />
   This variable holds the default HTML template for the row HTML list, It is used only when you call the<font color="#0000FF"> html_row_output($id)</font> method ... its an array and contains 5 elements required to build the row html menu.<br />
   <br />
   modify the template value as you want , but always remmeber to put your database columns between square brackets [] ( ie. &lt;a href=&quot;?id=<strong>[id]</strong>&quot;&gt;<strong>[article_name]</strong>&lt;/a&gt; ) <strong>[article_name]</strong> will be replaced with the actual article name from your database, same goes on <strong>[id]</strong>.<span class="normal_title"><br />
   <br />
   default value for the $HtmlRow Variable:</span><br /> 
   <br />
     </p>
 <div class="code_div"><font color="#ff8000">//&nbsp;HtmlTree&nbsp;is&nbsp;used&nbsp;with&nbsp;$this-&gt;html_row_output()&nbsp;method&nbsp;to&nbsp;print&nbsp;a&nbsp;You&gt;Are&gt;Here&nbsp;like&nbsp;menu <br />
 </font><font color="#0000bb">$this</font><font color="#007700">-&gt;</font><font color="#0000bb">HtmlRow&nbsp;</font><font color="#007700">=&nbsp;array( <br />
 </font><font color="#dd0000">&quot;OpenTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;div&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;the&nbsp;overall&nbsp;tag&nbsp;opener&nbsp;,&nbsp;example&nbsp;&lt;div&gt; <br />
 </font><font color="#dd0000">&quot;Seprator&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&nbsp;&amp;gt;&nbsp;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;seprator&nbsp;between&nbsp;the&nbsp;items.&nbsp;example&nbsp;&quot;&nbsp;&amp;gt;&nbsp;&quot;&nbsp;which&nbsp;means&nbsp;&quot;&nbsp;&gt;&nbsp;&quot; <br />
 </font><font color="#dd0000">&quot;NodeUnselected&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;[id]&lt;/a&gt;'</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;item&nbsp;tag&nbsp;..&nbsp; <br />
 </font><font color="#dd0000">&quot;NodeSelected&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;a&nbsp;href=&quot;?id=[id]&quot;&gt;&lt;strong&gt;[id]&lt;/strong&gt;&lt;/a&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;item&nbsp;tag&nbsp;..&nbsp;when&nbsp;selected&nbsp;! <br />
 </font><font color="#dd0000">&quot;CloseTag&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">=&gt;&nbsp;</font><font color="#dd0000">'&lt;/div&gt;'&nbsp;</font><font color="#007700">,&nbsp;</font><font color="#ff8000">//&nbsp;this&nbsp;is&nbsp;the&nbsp;overall&nbsp;tag&nbsp;opener&nbsp;,&nbsp;example&nbsp;&lt;div&gt; <br />
 </font><font color="#007700">); </font></div>
 <p class="normal">Sounds easy to understand ? .. if not yet , note to check the<a href="nodes_test.php"> nodes_test.php</a> usage example file </p>
 <hr />
 <p class="big_title">Main Functions/Methods: </p>
 <p class="medium_title">add_new<font size="1">($parent_id , $fields=array())</font>:</p>
 <p class="normal">this method is used to insert new node to the structure , it takes 2 params as the following: </p>
 <p class="normal"><span class="variable">$parent</span> : every node should have a parent node, if it doesn't then it will be a root node ... this variable holds the parent node ID or assign zero.</p>
 <p class="normal"><span class="variable">$fields: </span>array containing your column names as keys and data as values to be inserted into the MySQL table. </p>
 <p class="normal_title">example on method usage:</p>
 <div class="code_div"><font color="#0000bb">$fields = <font color="#007700"> array('c_name' =&gt; </font><font color="#0000bb">$_POST[c_name] </font><font color="#007700">,'c_desc' =&gt; </font><font color="#0000bb">$_POST[c_desc] </font><font color="#007700">)</font>;<br />
 $nodes-&gt;add_new</font><font color="#007700">(</font><font color="#0000bb">$parent </font><font color="#007700">,</font><font color="#007700">  $fields )</font>;</div>
 <hr />
 <p class="medium_title">update<font size="1">($node_id , $parent_id , $fields=array())</font>:</p>
 <p class="normal">this method is used to update existing node , it takes 5 params as the following: </p>
 <p class="normal"><span class="variable">$id</span>: the ID of node which you want to update. </p>
 <p class="normal"><span class="variable">$parent</span> : every node should have a parent node, if it doesn't then it will be a root node ... this variable holds the parent node ID otherwise assign zero, to prevent from a change pass the current node parent when updating :-) </p>
 <p class="normal"><span class="variable">$fields: </span>array containing your column names as keys and data as values </p>
 <p class="normal_title">example on method usage:</p>
 <div class="code_div"><font color="#0000bb">$fields = <font color="#007700"> array('c_name' =&gt; </font><font color="#0000bb">$_POST[c_name] </font><font color="#007700">,'c_desc' =&gt; </font><font color="#0000bb">$_POST[c_desc] </font><font color="#007700">)</font>;<br />
$nodes-&gt;update</font><font color="#007700">($id , </font><font color="#0000bb">$parent </font><font color="#007700">, $fields )</font>;</div>
 <hr />
 <p class="medium_title">delete<font size="1">($node_id)</font>:</p>
 <p class="normal">this method is used to delete existing node and all sub-nodes below it<br />
   it returns the deleted nodes IDs as array , so you could do later operations (i.e delete linked images or files )<br /> 
 needs 1 params as the following: </p>
 <p class="normal"><span class="variable">$id</span>: the ID of node which you want to delete. <br />
 </p>
 <p class="normal_title">example on method usage:</p>
 <div class="code_div"><font color="#0000bb">$deleted_nodes = delete</font><font color="#007700">(</font><font color="#0000bb">$id</font><font color="#007700">)</font>;<br />
 foreach($deleted as $node_id)<br />
 {<br />
   echo &quot;the node with the ID: &quot;.$node_id.&quot; was deleted &lt;br /&gt;&quot;;<br />
   <font color="#FF6600">// do your codes here </font><br />
   
}</div>
 <hr />
 <p class="medium_title">order_node<font size="1">($id , $new_order)</font>:</p>
 <p class="normal">this method is used to change the node display order inside its level.<br />
   to move the order up , just pass the current order minus 1 as the $new_order
   , same goes when moving down .. just add 1 to the current order. <br />
needs 2 params as the following: </p>
 <p class="normal"><span class="variable">$id</span>: the ID of node which you want to re-order. <br />
   <span class="variable">$new_order</span>: the new_order of the node .. don't care about giving wrong orders, the class handle it well! </p>
 <p class="normal_title">example on method usage:</p>
<div class="code_div">
  <p><font color="#0000bb">    <font color="#0000CC">$mynode = $nodes-&gt;fetch(&quot;4&quot;);
        <br />
        <font color="#FF6600">// lets move mynode up</font><br />
    $nodes-&gt;order_node($mynode</font></font><font color="#0000CC">['id'] , $mynode['ord'] - 1); <br />
    <font color="#FF6600"><br />
    // lets move mynode down </font><br />
  $nodes-&gt;order_node($mynode['id'] , $mynode['ord'] + 1);</font></p>
  <p><font color="#FF6600">// lets move mynode to the be the first in its list </font><font color="#0000CC"><br />
  $nodes-&gt;order_node($mynode['id'] , 1);</font></p>
  <p><font color="#FF6600">// lets move mynode to the be the last in its list </font><font color="#0000CC"><br />
  $nodes-&gt;order_node($mynode['id'] , -1 ); </font></p>
</div>
 <hr />
 <p>&nbsp;</p>
 <p class="medium_title">build_list<font size="1">($id , $clickable)</font>:</p>
 <p class="normal">this method is used to return an array with the categories,it takes  2 params as the following: </p>
 <p class="normal"><span class="variable">$id:</span> if you want to display an expanded list below a specific node fill its ID , otherwise the list will be expanded from the roots. </p>
 <p class="normal"><span class="variable">$clickable</span>: determine if the expanding level to be one-level only or unlimited. ( default is FALSE ) </p>
 <p>examples on method usage:</p>
 <p class="normal_title">General Usage </p>
 <div class="code_div"><font color="#0000bb">build_list</font><font color="#007700">(</font><font color="#0000bb">$id </font><font color="#007700">, </font><font color="#0000bb">$clickable</font><font color="#007700">)</font></div>
 <p><span class="normal">I'm going to explain some ways to use this method based on the following list example </span><strong>node_Name</strong>(<strong>ID</strong>) </p>
 <p class="normal">-Root1 (1)</p>
 <blockquote>
   <p class="normal">-Sub1-1 (2) </p>
   <blockquote>
     <p class="normal">-Sub1-1-1 (3)</p>
     <p class="normal">-Sub1-1-2 (4)</p>
   </blockquote>
   <p class="normal">-Sub1-2 (5)</p>
   <blockquote>
     <p class="normal">-Sub1-2-1 (6)</p>
   </blockquote>
 </blockquote>
 <p class="normal">-Root2 (7)	</p>
 <blockquote>
   <p class="normal">-Sub2-1 (8)</p>
   <p class="normal_title">&nbsp;</p>
 </blockquote>
 <p class="medium_title">Ok lets start ... 	</p>
 <p class="medium_title">&nbsp;</p>
 <p class="normal_title">To expand a root:</p>
 <p class="normal">-Root1 (1)</p>
 <blockquote>
   <p class="normal">-Sub1-1 (2) </p>
   <blockquote>
     <p class="normal">-Sub1-1-1 (3)</p>
     <p class="normal">-Sub1-1-2 (4)</p>
   </blockquote>
   <p class="normal">-Sub1-2 (5)</p>
   <blockquote>
     <p class="normal">-Sub1-2-1 (6)</p>
   </blockquote>
 </blockquote>
 <p class="normal">+Root2</p>
 <div class="code_div"><font color="#0000bb">build_list</font><font color="#007700">(</font> 1 <font color="#007700">)</font> <font color="#FF6600">// 1 is the ID of the root node</font> </div>
 <hr />
 <p class="normal_title">To display/open one-level only of expanded root:</p>
 <p class="normal">-Root1 (1)</p>
 <blockquote>
   <p class="normal">+Sub1-1 (2) </p>
   <p class="normal">+Sub1-2 (5)</p>
</blockquote>
 <p class="normal">+Root2</p>
 <div class="code_div"><font color="#0000bb">build_list</font><font color="#007700">(</font> 1 <font color="#0000bb"> </font><font color="#007700">,<font color="#0000bb">true</font></font><font color="#007700">)</font></div>
 <hr />
 <p class="normal_title">To display/open one-level only of a child node:</p>
 <p class="normal">-Root1 (1)</p>
 <blockquote>
   <p class="normal">-Sub1-1 (2) </p>
   <blockquote>
     <p class="normal">+Sub1-1-1 (3)</p>
     <p class="normal">+Sub1-1-2 (4)</p>
   </blockquote>
   <p class="normal">+Sub1-2 (5)</p>
 </blockquote>
 <p class="normal">+Root2</p>
 <div class="code_div"><font color="#0000bb">build_list</font><font color="#007700">(</font> 2 <font color="#0000bb"> </font><font color="#007700">,<font color="#0000bb">true</font></font><font color="#007700">)</font></div>
 <hr />
 <p class="normal_title">And finally to display the full expanded list:</p>
 <p class="normal">-Root1 (1)</p>
 <blockquote>
   <p class="normal">-Sub1-1 (2) </p>
   <blockquote>
     <p class="normal">-Sub1-1-1 (3)</p>
     <p class="normal">-Sub1-1-2 (4)</p>
   </blockquote>
   <p class="normal">-Sub1-2 (5)</p>
   <blockquote>
     <p class="normal">-Sub1-2-1 (6)</p>
   </blockquote>
 </blockquote>
 <p class="normal">-Root2 (7) </p>
<blockquote>
   <p class="normal">-Sub2-1 (8)</p>
</blockquote>
 <div class="code_div"><font color="#0000bb">build_list</font><font color="#007700">(</font><font color="#0000bb"> 0 </font><font color="#007700">)</font></div>
 <hr />
 <p class="style2">browse_by_id<font size="1">($id)</font>:</p>
 <p class="style1">this function returns an array of sub-nodes within a specific node .. and takes the parent node ID as a param<span class="variable"> $id </span></p>
 <div class="code_div"><font color="#0000bb">browse_by_id</font><font color="#007700">(</font><font color="#0000bb"> $id = 0 </font><font color="#007700">)</font></div>
 <hr />
 <p class="style2">fetch<font size="1">($id)</font>:</p>
 <p class="style1">very useful function. <br />
 this function returns the node info from database as array.. and takes the node ID as a param<span class="variable"> $id </span></p>
 <div class="code_div"><font color="#0000bb">fetch</font><font color="#007700">(</font>$id<font color="#0000bb">  </font><font color="#007700">)</font></div>
 <hr />
 <p class="style2">html_output<font size="1">($id , $clickable = false)</font>:</p>
 <p class="style1">this function returns the HTML list output,  and takes the selected node ID as a param or it will print the roots list.</p>
 <p class="style1">you can modify the template of the list by modifying the $HtmlTree variable as showen above.</p>
 <p class="style1">this function is useful when you want to print a Clickable list too depending on the selected node ID. (same as build_list() method above) </p>
 <div class="code_div"><font color="#0000bb">html_output</font><font color="#007700">(</font><font color="#0000bb">$id</font><font color="#007700"> , $clickable = false)</font></div>
<hr />
 <p class="style2"><br />
 html_row_output<font size="1">($id)</font>:</p>
 <p class="style1">this function returns the row HTML list (You&gt;Are&gt;Here like menu) output,  and takes the selected node ID as a param or it will print the roots list.</p>
 <p class="style1">you can modify the template of the list by modifying the $HtmlRow variable as showen above.</p>
 <p class="style1">&nbsp;</p>
 <div class="code_div"><font color="#0000bb">html_row_output</font><font color="#007700">(</font><font color="#0000bb">$id</font><font color="#007700">)</font> <font color="#FF6600">// pass the id of the current node id.</font></div>
 <hr />
 <hr />
 <p class="medium_title">count_nodes:</p>
 <p class="normal">this function returns how many sub nodes in below the given node ID,  and takes parent node ID as a param.</p>
 <div class="code_div"><font color="#0000bb">count_nodes($id);</font></div>
 <hr />
 <p class="big_title"><strong><font color="#007700"> Manual End.</font></strong></p>
 <p>Shadi Ali<br />
 hide@address.com<br />
 Feb/03/2007 </p>
 <p>&nbsp;</p>
 <div style="border:thick dashed #FF0000; padding:5px; margin:10px; background-color:#FFFFCC">
   <p><strong><font color="#FF0000" size="5">Please Wait!</font></strong></p>
   <p>almost half of the development time for this class was in writing these documentation and usage example, so I'm asking you of three things to do for me as a favour .. ( Money Not Included!!)</p>
   <ol>
     <li>Forgive me for any faults in the documentations and always remmeber that english isn't my native language.</li>
     <li>Report any bugs at my email address or at phpclasses.org class forum</li>
     <li>Spread this class to help other programmers save their precious time.<br />
     </li>
   </ol>
   <p><strong>Thank You.</strong> <br />
   Shadi Ali<br />
hide@address.com<br />
Feb/03/2007 </p>
 </div>
 <p>&nbsp;</p>
</body>
</html>
Return current item: Nested Nodes Class