Location: PHPKode > scripts > TreeMenu > treemenu/exanple1.php
Test Setmenu<BR>
<?
INCLUDE_ONCE( "Set_Menu.php" );

/*
	menu_id is ID of menu.
	parent_id is ID of menu's parent.
	order is order in that menu group.
*/

                     //    v-----------  Array Index is menu_id,  
					 //                   Array Index must start at 1 and $data_menu_array[ 1 ][ "parent_id" ] must is 0.
$data_menu_array[ 1 ][ "menu_id" ]			= 1;
$data_menu_array[ 1 ][ "parent_id" ]			= 0;
$data_menu_array[ 1 ][ "order" ]				= 1;
$data_menu_array[ 1 ][ "name" ]				= "Menu 1";

$data_menu_array[ 2 ][ "menu_id" ]			= 2;
$data_menu_array[ 2 ][ "parent_id" ]			= 1;
$data_menu_array[ 2 ][ "order" ]				= 1;
$data_menu_array[ 2 ][ "name" ]				= "Menu 2";

$data_menu_array[ 3 ][ "menu_id" ]			= 3;
$data_menu_array[ 3 ][ "parent_id" ]			= 2;
$data_menu_array[ 3 ][ "order" ]				= 1;
$data_menu_array[ 3 ][ "name" ]				= "Menu 3";

$data_menu_array[ 4 ][ "menu_id" ]			= 4;
$data_menu_array[ 4 ][ "parent_id" ]			= 2;
$data_menu_array[ 4 ][ "order" ]				= 1;
$data_menu_array[ 4 ][ "name" ]				= "Menu 4";

$data_menu_array[ 5 ][ "menu_id" ]			= 5;
$data_menu_array[ 5 ][ "parent_id" ]			= 2;
$data_menu_array[ 5 ][ "order" ]				= 1;
$data_menu_array[ 5 ][ "name" ]				= "Menu 5";

$data_menu_array[ 6 ][ "menu_id" ]			= 6;
$data_menu_array[ 6 ][ "parent_id" ]			= 2;
$data_menu_array[ 6 ][ "order" ]				= 1;
$data_menu_array[ 6 ][ "name" ]				= "Menu 6";

$data_menu_array[ 7 ][ "menu_id" ]			= 7;
$data_menu_array[ 7 ][ "parent_id" ]			= 1;
$data_menu_array[ 7 ][ "order" ]				= 1;
$data_menu_array[ 7 ][ "name" ]				= "Menu 7";

$data_menu_array[ 8 ][ "menu_id" ]			= 8;
$data_menu_array[ 8 ][ "parent_id" ]			= 7;
$data_menu_array[ 8 ][ "order" ]				= 1;
$data_menu_array[ 8 ][ "name" ]				= "Menu 8";

$data_menu_array[ 9 ][ "menu_id" ]			= 9;
$data_menu_array[ 9 ][ "parent_id" ]			= 8;
$data_menu_array[ 9 ][ "order" ]				= 1;
$data_menu_array[ 9 ][ "name" ]				= "Menu 9";

$data_menu_array[ 10 ][ "menu_id" ]		= 10;
$data_menu_array[ 10 ][ "parent_id" ]		= 9;
$data_menu_array[ 10 ][ "order" ]				= 1;
$data_menu_array[ 10 ][ "name" ]			= "Menu 10";

$data_menu_array[ 11 ][ "menu_id" ]		= 11;
$data_menu_array[ 11 ][ "parent_id" ]		= 10;
$data_menu_array[ 11 ][ "order" ]				= 1;
$data_menu_array[ 11 ][ "name" ]			= "Menu 11";

$data_menu_array[ 12 ][ "menu_id" ]		= 12;
$data_menu_array[ 12 ][ "parent_id" ]		= 10;
$data_menu_array[ 12 ][ "order" ]				= 1;
$data_menu_array[ 12 ][ "name" ]			= "Menu 12";

$data_menu_array[ 13 ][ "menu_id" ]		= 13;
$data_menu_array[ 13 ][ "parent_id" ]		= 10;
$data_menu_array[ 13 ][ "order" ]				= 1;
$data_menu_array[ 13 ][ "name" ]			= "Menu 13";

$data_menu_array[ 14 ][ "menu_id" ]		= 14;
$data_menu_array[ 14 ][ "parent_id" ]		= 10;
$data_menu_array[ 14 ][ "order" ]				= 1;
$data_menu_array[ 14 ][ "name" ]			= "Menu 14";

$data_menu_array[ 15 ][ "menu_id" ]		= 15;
$data_menu_array[ 15 ][ "parent_id" ]		= 3;
$data_menu_array[ 15 ][ "order" ]				= 1;
$data_menu_array[ 15 ][ "name" ]			= "Menu 15";

$data_menu_array[ 16 ][ "menu_id" ]		= 16;
$data_menu_array[ 16 ][ "parent_id" ]		= 3;
$data_menu_array[ 16 ][ "order" ]				= 1;
$data_menu_array[ 16 ][ "name" ]			= "Menu 16";

$data_menu_array[ 17 ][ "menu_id" ]		= 17;
$data_menu_array[ 17 ][ "parent_id" ]		= 3;
$data_menu_array[ 17 ][ "order" ]				= 1;
$data_menu_array[ 17 ][ "name" ]			= "Menu 17";

$data_menu_array[ 18 ][ "menu_id" ]		= 18;
$data_menu_array[ 18 ][ "parent_id" ]		= 9;
$data_menu_array[ 18 ][ "order" ]				= 1;
$data_menu_array[ 18 ][ "name" ]			= "Menu 18";

$data_menu_array[ 19 ][ "menu_id" ]		= 19;
$data_menu_array[ 19 ][ "parent_id" ]		= 9;
$data_menu_array[ 19 ][ "order" ]				= 1;
$data_menu_array[ 19 ][ "name" ]			= "Menu 19";

$data_menu_array[ 20 ][ "menu_id" ]		= 20;
$data_menu_array[ 20 ][ "parent_id" ]		= 9;
$data_menu_array[ 20 ][ "order" ]				= 1;
$data_menu_array[ 20 ][ "name" ]			= "Menu 20";

$data_menu_array[ 21 ][ "menu_id" ]		= 21;
$data_menu_array[ 21 ][ "parent_id" ]		= 1;
$data_menu_array[ 21 ][ "order" ]				= 13;
$data_menu_array[ 21 ][ "name" ]			= "Menu 21";

$data_menu_array[ 22 ][ "menu_id" ]		= 22;
$data_menu_array[ 22 ][ "parent_id" ]		= 1;
$data_menu_array[ 22 ][ "order" ]				= 10;
$data_menu_array[ 22 ][ "name" ]			= "Menu 22";

$data_menu_array[ 23 ][ "menu_id" ]		= 23;
$data_menu_array[ 23 ][ "parent_id" ]		= 1;
$data_menu_array[ 23 ][ "order" ]				= 18;
$data_menu_array[ 23 ][ "name" ]			= "Menu 23";

$data_menu_array[ 24 ][ "menu_id" ]		= 24;
$data_menu_array[ 24 ][ "parent_id" ]		= 1;
$data_menu_array[ 24 ][ "order" ]				= 16;
$data_menu_array[ 24 ][ "name" ]			= "Menu 24";

$data_menu_array[ 25 ][ "menu_id" ]		= 25;
$data_menu_array[ 25 ][ "parent_id" ]		= 1;
$data_menu_array[ 25 ][ "order" ]				= 3;
$data_menu_array[ 25 ][ "name" ]			= "Menu 25";

$data_menu_array[ 26 ][ "menu_id" ]		= 26;
$data_menu_array[ 26 ][ "parent_id" ]		= 1;
$data_menu_array[ 26 ][ "order" ]				= 2;
$data_menu_array[ 26 ][ "name" ]			= "Menu 26";

$data_menu_array[ 27 ][ "menu_id" ]		= 27;
$data_menu_array[ 27 ][ "parent_id" ]		= 1;
$data_menu_array[ 27 ][ "order" ]				= 9;
$data_menu_array[ 27 ][ "name" ]			= "Menu 27 <FONT Color=\"red\">Reorder by order number.</FONT>";

$data_menu_array[ 28 ][ "menu_id" ]		= 28;
$data_menu_array[ 28 ][ "parent_id" ]		= 1;
$data_menu_array[ 28 ][ "order" ]				= 5;
$data_menu_array[ 28 ][ "name" ]			= "Menu 28";

$data_menu_array[ 29 ][ "menu_id" ]		= 29;
$data_menu_array[ 29 ][ "parent_id" ]		= 1;
$data_menu_array[ 29 ][ "order" ]				= 4;
$data_menu_array[ 29 ][ "name" ]			= "Menu 29";

$data_menu_array[ 30 ][ "menu_id" ]		= 30;
$data_menu_array[ 30 ][ "parent_id" ]		= 1;
$data_menu_array[ 30 ][ "order" ]				= 20;
$data_menu_array[ 30 ][ "name" ]			= "Menu 30";

$data_menu_array[ 31 ][ "menu_id" ]		= 31;
$data_menu_array[ 31 ][ "parent_id" ]		= 1;
$data_menu_array[ 31 ][ "order" ]				= 15;
$data_menu_array[ 31 ][ "name" ]			= "Menu 31";

$data_menu_array[ 32 ][ "menu_id" ]		= 32;
$data_menu_array[ 32 ][ "parent_id" ]		= 1;
$data_menu_array[ 32 ][ "order" ]				= 19;
$data_menu_array[ 32 ][ "name" ]			= "Menu 32";

$data_menu_array[ 33 ][ "menu_id" ]		= 33;
$data_menu_array[ 33 ][ "parent_id" ]		= 1;
$data_menu_array[ 33 ][ "order" ]				= 30;
$data_menu_array[ 33 ][ "name" ]			= "Menu 33";

//$param1 = "Link";
$treemenu_obj = NEW tree_menu;
$tree_menu = $treemenu_obj->set_menu ( $data_menu_array, $param1 , $param2  );
//---------------------------------------------------------------------------------------------------------------------
// Sturcture of $tree_menu.
/*
		$tree_menu[ "row" ][ "column" ][ "menu_id" ]		= ID of Menu.
                                                  [ "sign_no" ]		= Number of join sign.
																			0 or empty		is  no sign.
																			1					is line sign.				( | )
																			2					is join sign.				( + )
																			3					is joinbottom sign.	( L )

*/
//---------------------------------------------------------------------------------------------------------------------
/*
WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) ) {
		// -v- WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) )
		ECHO $key." => ".$val."<BR>";
		WHILE ( LIST( $key1, $val1 ) = EACH( $val ) ) {
			// -v- WHILE ( LIST( $key1, $val1 ) = EACH( $val ) )
			ECHO "=================".$key1." => ".$val1."<BR>";
			WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) ) {
				// -v- WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) )
				ECHO "------------------------------------------------------------------".$key2." => ".$val2."<BR>";
			}		// -^- WHILE ( LIST( $key2, $val2 ) = EACH( $val1 ) )
		}		// -^- WHILE ( LIST( $key1, $val1 ) = EACH( $val ) )
}		// -^- WHILE ( LIST( $key, $val ) = EACH( $tree_menu ) )
*/


		$table_menu_data = $tree_menu;
		ECHO "<TABLE Border=0 cellpadding=\"0\" cellspacing=\"0\">\n";
		WHILE ( LIST( $key, $val ) = EACH( $table_menu_data ) ) {	// -v- WHILE ( LIST( $key, $val ) = EACH( $table_menu_data ) )
			ECHO "<TR><TD><TABLE Border=0 cellpadding=\"0\" cellspacing=\"0\"><TR><TD>\n";
			WHILE ( LIST( $key1, $val1 ) = EACH( $val ) ) {	// -v- WHILE ( LIST( $key, $val ) = EACH( $val ) )
				IF ( $key == 1 ) {
									// -v- IF ( $key == 1 )
					$path_gif = "empty.gif";
				}ELSE {			// --- IF ( $key == 1 )
					SWITCH ( $val1["sign_no"] ) {		// -v- SWITCH ( $val1["sign_no"] )
						CASE "0" : $path_gif = "empty.gif";				BREAK;
						CASE "1" : $path_gif = "line.gif";					BREAK;
						CASE "2" : $path_gif = "join.gif";					BREAK;
						CASE "3" : $path_gif = "joinbottom.gif";		BREAK;
						DEFAULT : $path_gif = "empty.gif";				BREAK;
					}											// -^- SWITCH ( $val1["sign_no"] )
				}					// -^- IF ( $key == 1 )
				
				IF ( $val1[ "menu_id" ] > 0 ) {		// -v- IF ( $val1[ "menu_id" ] > 0 )
					//ECHO "<TD><IMG SRC=\"../images/line/".$path_gif."\"></TD>\n";
					ECHO "<TD><IMG SRC=\"".$path_gif."\"></TD>\n";
					ECHO "<TD><FONT Size=\"2\">&nbsp;".$data_menu_array[ $val1["menu_id"] ][ "name" ]."</FONT>&nbsp;&nbsp;<FONT Color=\"green\" Size=\"1\">Parent is ".$data_menu_array[$data_menu_array[ $val1["menu_id"] ][ "parent_id" ]][ "name" ]."</FONT>&nbsp;&nbsp;<FONT Color=\"blue\" Size=\"1\">Order No. ".$data_menu_array[ $val1["menu_id"] ][ "order" ]."</FONT></TD>\n";
				}ELSE {									// --- IF ( $val1[ "menu_id" ] > 0 )
					ECHO "<TD><IMG SRC=\"".$path_gif."\"></TD>\n";
				}											// -^- IF ( $val1[ "menu_id" ] > 0 )
			}																// -^- WHILE ( LIST( $key, $val ) = EACH( $val ) )
			ECHO "</TD></TR></TABLE></TD></TR>\n";
		}																				// -^- WHILE ( LIST( $key, $val ) = EACH( $table_menu_data ) )
		UNSET( $key, $val );
		UNSET( $key1, $val1 );
		ECHO "</TABLE>\n";
?>
Return current item: TreeMenu