Results 1 to 7 of 7

Thread: Generating HVmenu in php

  1. #1
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generating HVmenu in php

    Hello boys ang girls ... what`s up ?
    I Have A Big Problem but first let me tell you the story ....
    ----------
    1.) 1(one) MySQL DB like this:
    # MySQL-Front Dump 2.5
    #
    # Host: localhost Database: hvmenu
    # --------------------------------------------------------
    # Server version 3.23.55
    #
    # Table structure for table 'menu'
    #

    DROP TABLE IF EXISTS `menu`;
    CREATE TABLE `menu` (
    `id` int(10) unsigned NOT NULL auto_increment,
    `text` varchar(255) NOT NULL default '0',
    `link` varchar(255) NOT NULL default '0',
    `is_parent` int(3) default NULL,
    `who_is_father` int(3) NOT NULL default '0',
    `subclass_level` int(3) NOT NULL default '0',
    PRIMARY KEY (`id`),
    UNIQUE KEY `id` (`id`),
    KEY `id_2` (`id`)
    ) TYPE=MyISAM;



    #
    # Dumping data for table 'menu'
    #

    INSERT INTO `menu` (`id`, `text`, `link`, `is_parent`, `who_is_father`, `subclass_level`) VALUES("1", "First Level 1", "#", "1", "0", "1");
    INSERT INTO `menu` (`id`, `text`, `link`, `is_parent`, `who_is_father`, `subclass_level`) VALUES("2", "Second Level 1", "#", "0", "1", "2");
    INSERT INTO `menu` (`id`, `text`, `link`, `is_parent`, `who_is_father`, `subclass_level`) VALUES("3", "Second Level 2", "#", "1", "3", "2");
    INSERT INTO `menu` (`id`, `text`, `link`, `is_parent`, `who_is_father`, `subclass_level`) VALUES("4", "Third Level 1", "#", "0", "2", "3");
    INSERT INTO `menu` (`id`, `text`, `link`, `is_parent`, `who_is_father`, `subclass_level`) VALUES("5", "Third Level 2", "#", "0", "2", "3");
    ========
    2). 1(one) kick-A** PHP script that has a problem. I know it has a problem but i cand find ANY SOLUTION to try to fix this problem !

    <?
    //let's calculate the max number of sub-levels
    $j = 1;
    for ($i=1; $i<=$j; $i++) {
    $query = "SELECT * FROM `menu` WHERE `subclass_level`='".$i."'";
    $result = mysql_query($query) or die(mysql_error().":".mysql_errno());
    $go = false;
    while ($info = mysql_fetch_array($result)) {
    if ($go == false) {
    if ($info["is_parent"] == 1) { $j++; $go = true;}
    }//end if
    }//end while
    }//end for
    //end calc submivele



    for ($i=1; $i<=$j; $i++) {
    $query = "SELECT * FROM `menu` WHERE `subclass_level`='".$i."'";
    $result = mysql_query($query) or die(mysql_error().":".mysql_errno());
    $k = 1; /* $k is the value of the row*/
    while ($info = mysql_fetch_array($result)) {
    if ($info["is_parent"] == 1) {
    $cate = mysql_num_rows(mysql_query("SELECT * FROM `menu` WHERE `who_is_father`='".$info["id"]."' AND `subclass_level`='".($i+1)."'"));
    echo "Menu".$help_me." = new Array('".$info["text"]."','".$info["link"]."','','".$cate."');\n";
    } else {
    echo "Menu".$help_me." = new Array('".$info["text"]."','".$info["link"]."','','0');\n";
    }
    $k++;
    } //end while
    } //end for
    ?>
    ==================
    ok so my problem is that i don't have the smallest ideea in how to create the sublevel number in HVmenu like: Menu1_2_2_3_3 for unlimited levels !

    if YOU can help me with this script (i mean if you can create some kind of strange function that i could not think about or modify the script a "little") then help me it`s a nice challange.

    p.S. If you have another solution how i can generate HV menu with unlimited submenus that are extracted from a MYSQL DB then please, please, please HELP !!!!

  2. #2
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Right, bloody vbulliten just logged me out the first time trying to post this monster, so will be posted in multiple posts.

    I have sucessfully created a php script, which generates the config file for hvmenu.

    The idea behind this is to allow us to populate the java menu dynamically from our list of product categories, which are stored in a mysql database as a nested set. (see: http://dev.mysql.com/tech-resources/...ical-data.html
    )

    Now our site is broken down into a lot offunctions, so theres a lot of code!

    My main issues are firstly actually getting this to display on our page!
    With the example script which comes with it, i can change the config file path to my php script, and it all works fine.
    but on my main page, there is nothing.
    Ive tried al manner of different configs for relative positioning, the frame names and targets etc etc, all to no avail.

    The second php glitch, you will see in functions.php.
    I have to go through a switch($depth){ case 0, case 1, case 2, through to 10.
    there is a commented out for loop, which never returns a value. (commented cause it doesnt work! ...I thought id edit that before someone points it out :P )

    Another Edit:
    So you know what this script was designed to achieve, take a look at http://topclasscarpentry.com/buildin...ucts/index.php

    The Product Categories list on the side is a hierarchical list. This javascript will replace our current nav bar, so that the products menu is dynamically generated.
    Last edited by tandyuk; 03-31-2006 at 06:21 PM.

  3. #3
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    menu_com.js - totally untouched!


    Now the config file is built from our db.
    First the db structure:

    Code:
    CREATE TABLE `category` (
      `cat_id` int(11) NOT NULL auto_increment,
      `cat_name` varchar(45) character set latin1 NOT NULL default '',
      `lft` int(11) NOT NULL default '0',
      `rgt` int(11) NOT NULL default '0',
      `description` varchar(100) default NULL,
      `image` int(10) unsigned NOT NULL default '135',
      PRIMARY KEY  (`cat_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8

    Now the code from category.php, this loads the list of categories, and their depth in the hierarchy (used to work out the prefix), and a function to count the sub categories of a node.

    category.php
    Code:
    // Query all catagories	of products
    	function QueryAllCatagories(){
    		global $database, $all_catagory_results;
    		$q = "SELECT node.cat_id as id, count(parent.cat_name) -1 as depth, node.cat_name as cat_name from category as node, category as parent WHERE node.lft BETWEEN parent.lft and parent.rgt group by node.cat_name order by node.lft;";
    		$all_catagory_results = $database->query($q);
    	}	
    	
    	function CountSubCatsOnly($name){
    		global $database;
    		$q = "SELECT node.cat_name, (COUNT(parent.cat_name) - (sub_tree.depth + 1)) AS depth FROM category AS node, category AS parent,	category AS sub_parent,(SELECT node.cat_name, (COUNT(parent.cat_name) - 1) AS depth	FROM category AS node, category AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.cat_name = '$name' GROUP BY node.cat_name ORDER BY node.lft) AS sub_tree WHERE node.lft BETWEEN parent.lft AND parent.rgt AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt AND sub_parent.cat_name = sub_tree.cat_name GROUP BY node.cat_name HAVING depth = 1 ORDER BY node.lft;";
    		$result = $database->query($q);
    		$subcats = mysql_num_rows($result);
    		return($subcats);
    	}

  4. #4
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    jsdropdown.php - This is our php script which generates the javascript config file.

    Code:
    <?PHP
    include_once("../product-catagory/functions.php");
    include_once("../product-catagory/category.php");
    include_once("../login/include/database.php");
    QueryAllCatagories();
    echo BuildJSMenu();
    ?>
    Now the function which does all the work...
    In this function, the other 6 main menu items which arent dynamic (YET ) are defined too.
    functions.php

    Code:
    function BuildJSMenu() {
    	global	$all_catagory_results;
    			
    		// Menu tree
    //	MenuX=new Array(Text to show, Link, background image (optional), number of sub elements, height, width);
    //	For rollover images set "Text to show" to:  "rollover:Image1.jpg:Image2.jpg"
    
    	$topmenu = 2;
    	$toplevels = 0;
    	$toptarget = "category";
    	$lastdepth = -1;
    	$maxdepth = 10;
    	for($i=0;$i==$maxdepth;$i++){
    		${"counter".$i} = 0;
    	}
    	
    	$rows = mysql_num_rows($all_catagory_results);
    	for($i=0;$i<$rows;$i++){
    		$depth = mysql_result($all_catagory_results,$i,"depth");
    		$name = mysql_result($all_catagory_results,$i,"cat_name");
    		$subcats = CountSubCatsOnly($name);
    		if($depth!==$lastdepth){
    			if($depth<$lastdepth) {
    				//reset sub counters
    				for($d=($depth+1);$d==$maxdepth;$d++){
    					${"counter".$d} = 0;
    				}
    			}
    		}
    		
    		${"counter".$depth}++;
    		//construct the menu name:
    		
    		switch($depth){
    		case "0":
    			$toplevels++;
    			$prefix = "_" . $counter0;
    		break;
    		case "1":
    		$prefix = "_" . $counter0 . "_" . $counter1;
    		break;
    		case "2":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2;
    		break;
    		case "3":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3;
    		break;
    		case "4":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4;
    		break;	
    		case "5":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5;
    		break;	
    		case "6":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5 . "_" . $counter6;
    		break;	
    		case "7":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5 . "_" . $counter6 . "_" . $counter7;
    		break;	
    		case "8":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5 . "_" . $counter6 . "_" . $counter7 . "_" . $counter8;
    		break;	
    		case "9":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5 . "_" . $counter6 . "_" . $counter7 . "_" . $counter8 . "_" . $counter9;
    		break;	
    		case "10":
    		$prefix = "_" . $counter0 . "_" . $counter1 . "_" . $counter2 . "_" . $counter3 . "_" . $counter4 . "_" . $counter5 . "_" . $counter6 . "_" . $counter7 . "_" . $counter8 . "_" . $counter9 . "_" . $counter10;
    		break;					
    		}
    			
    		/*   PLEASE HELP ME MKAE THIS WORK!!! LOL
    			$prefix = "";
    			$startdepth = $depth+1;
    			
    		for($d=0;$d==$startdepth;$d++){
    			$prefix .= "_" . ${"counter$d"};
    		}			
    			*/	
    		$java .= "Menu" .$topmenu . $prefix . "=new Array(\"". $name . "\",\"" . BuildURL($toptarget,$name) . "\",\"\"," . $subcats . ",20,150);\n";
    			
    	$lastdepth = $depth;
    	}
    		
    	$prejava = "/***********************************************************************************
    *	(c) Ger Versluis 2000 version 5.411 24 December 2001 (updated Jan 31st, 2003 by Dynamic Drive for Opera7)
    *	For info write to menus@burmees.nl		          *
    *	You may remove all comments for faster loading	          *		
    ***********************************************************************************/
    	var NoOffFirstLineMenus=7;			// Number of first level items
    	var LowBgColor='white';			// Background color when mouse is not over
    	var LowSubBgColor='white';			// Background color when mouse is not over on subs
    	var HighBgColor='black';			// Background color when mouse is over
    	var HighSubBgColor='black';			// Background color when mouse is over on subs
    	var FontLowColor='black';			// Font color when mouse is not over
    	var FontSubLowColor='black';			// Font color subs when mouse is not over
    	var FontHighColor='white';			// Font color when mouse is over
    	var FontSubHighColor='white';			// Font color subs when mouse is over
    	var BorderColor='black';			// Border color
    	var BorderSubColor='black';			// Border color for subs
    	var BorderWidth=1;				// Border width
    	var BorderBtwnElmnts=1;			// Border between elements 1 or 0
    	var FontFamily=\"arial,comic sans ms,technical\";	// Font family menu items
    	var FontSize=9;				// Font size menu items
    	var FontBold=1;				// Bold menu items 1 or 0
    	var FontItalic=0;				// Italic menu items 1 or 0
    	var MenuTextCentered='left';			// Item text position 'left', 'center' or 'right'
    	var MenuCentered='left';			// Menu horizontal position 'left', 'center' or 'right'
    	var MenuVerticalCentered='top';		// Menu vertical position 'top', 'middle','bottom' or static
    	var ChildOverlap=.2;				// horizontal overlap child/ parent
    	var ChildVerticalOverlap=.2;			// vertical overlap child/ parent
    	var StartTop=0;				// Menu offset x coordinate
    	var StartLeft=0;				// Menu offset y coordinate
    	var VerCorrect=0;				// Multiple frames y correction
    	var HorCorrect=0;				// Multiple frames x correction
    	var LeftPaddng=3;				// Left padding
    	var TopPaddng=2;				// Top padding
    	var FirstLineHorizontal=1;			// SET TO 1 FOR HORIZONTAL MENU, 0 FOR VERTICAL
    	var MenuFramesVertical=1;			// Frames in cols or rows 1 or 0
    	var DissapearDelay=1000;			// delay before menu folds in
    	var TakeOverBgColor=0;			// Menu frame takes over background color subitem frame
    	var FirstLineFrame='_top';			// Frame where first level appears
    	var SecLineFrame='_top';			// Frame where sub levels appear
    	var DocTargetFrame='_top';			// Frame where target documents appear
    	var TargetLoc='';				// span id for relative positioning
    	var HideTop=0;				// Hide first level when loading new document 1 or 0
    	var MenuWrap=1;				// enables/ disables menu wrap 1 or 0
    	var RightToLeft=0;				// enables/ disables right to left unfold 1 or 0
    	var UnfoldsOnClick=0;			// Level 1 unfolds onclick/ onmouseover
    	var WebMasterCheck=0;			// menu tree checking on or off 1 or 0
    	var ShowArrow=1;				// Uses arrow gifs when 1
    	var KeepHilite=1;				// Keep selected path highligthed
    	var Arrws=['/images/tri.gif',5,10,'/images/tridown.gif',10,5,'/images/trileft.gif',5,10];	// Arrow source, width and height
    function BeforeStart(){return}
    function AfterBuild(){return}
    function BeforeFirstOpen(){return}
    function AfterCloseAll(){return}
    // Menu tree
    //	MenuX=new Array(Text to show, Link, background image (optional), number of sub elements, height, width);
    //	For rollover images set \"Text to show\" to:  \"rollover:Image1.jpg:Image2.jpg\"
    Menu1=new Array(\"Main\",\"/index.php\",\"\",0,20,100);
    ";
    
    	$menu2java = "Menu2=new Array(\"Products\",\"/products/index.php\",\"\",%d,20,150);\n";
    		
    	$postjava = "
    Menu3=new Array(\"Services\",\"/services/index.php\",\"\",8,20,150);
    Menu3_1=new Array(\"Carpentry\",\"" . BuildURL("service","Carpentry","Contractor") . "\",\"\",0,20,150);
    Menu3_2=new Array(\"Flooring\",\"" . BuildURL("service","Flooring","Fitter") . "\",\"\",0,20,150);
    Menu3_3=new Array(\"Electrical\",\"" . BuildURL("service","Electrical","Contractor") . "\",\"\",0,20,150);
    Menu3_4=new Array(\"Brick Laying\",\"" . BuildURL("service","Brick Laying","Contractor") . "\",\"\",0,20,150);
    Menu3_5=new Array(\"Plastering\",\"" . BuildURL("service","Plastering","Contractor") . "\",\"\",0,20,150);
    Menu3_6=new Array(\"Artexing\",\"" . BuildURL("service","Artexing","Contractor") . "\",\"\",0,20,150);
    Menu3_7=new Array(\"Coving\",\"" . BuildURL("service","Coving","Contractor") . "\",\"\",0,20,150);
    Menu3_8=new Array(\"Tiling\",\"" . BuildURL("service","Tiling","Contractor") . "\",\"\",0,20,150);
    Menu4=new Array(\"Guides\",\"/kitchen-planning-guide/index.php\",\"\",2,20,150);
    Menu4_1=new Array(\"Kitchen Planning Guide\",\"/kitchen-planning-guide/index.php\",\"\",0,20,150);
    Menu4_2=new Array(\"Part E Regulation Guide\",\"/guide-to-part-e-regulations.php\",\"\",0,20,150);
    Menu5=new Array(\"Portfolio\",\"/portfolio/index.php\",\"\",8,20,150);
    Menu5_1=new Array(\"Laminate Flooring\",\"" . BuildURL("portfolio","Laminate Flooring") . "\",\"\",0,20,150);
    Menu5_2=new Array(\"Radiator Covers\",\"" . BuildURL("portfolio","Radiator Covers") . "\",\"\",0,20,150);
    Menu5_3=new Array(\"Ceramic Tiling\",\"" . BuildURL("portfolio","Ceramic Tiling") . "\",\"\",0,20,150);
    Menu5_4=new Array(\"Home Refurbishment\",\"" . BuildURL("portfolio","Home Refurbishment") . "\",\"\",0,20,150);
    Menu5_5=new Array(\"Hot Tub Enclosures\",\"" . BuildURL("portfolio","Hot Tub Enclosures") . "\",\"\",0,20,150);
    Menu5_6=new Array(\"Home Offices\",\"" . BuildURL("portfolio","Home Offices") . "\",\"\",0,20,150);
    Menu5_7=new Array(\"Entrance Gates\",\"" . BuildURL("portfolio","Entrance Gates") . "\",\"\",0,20,150);
    Menu5_8=new Array(\"Custom Made Cupboards\",\"" . BuildURL("portfolio","Custom Made Cupboards") . "\",\"\",0,20,150);
    Menu6=new Array(\"Contact\",\"/contact.php\",\"\",0,20,150);
    Menu7=new Array(\"Directory\",\"/top-class-web-directory/index.php\",\"\",0,20,150);";
    		
    
    $finaljava = $prejava . sprintf($menu2java,$toplevels) . $java . $postjava;
    
    	return ($finaljava);
    }

  5. #5
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    finally, this is the code echoed in our page class to (try to) display the navbar

    Code:
    var $HTMLNavBar = "<tr><th colspan=\"3\"><div style='position:relative' id=\"navbarheader\"></div><SCRIPT language=\"javascript\" type=\"text/javascript\">
    		<!--
    //HV Menu- by Ger Versluis (http://www.burmees.nl/)
    //Submitted to Dynamic Drive (http://www.dynamicdrive.com)
    //Visit http://www.dynamicdrive.com for this script and more
    
    function Go(){return}
    
    //--></SCRIPT>
    		<script language=\"javascript\" type=\"text\javascript\" src=\"/scripts/jsdropdown.php\"></script><script language=\"javascript\" type=\"text\javascript\" src=\"/scripts/menu_com.js\"></script></th></tr></table>";
    This is correctly echoed to the page, however no navbar ever appears.
    To confirm the php part is correct, i can call the following example page and get the navbar as it should appear, and with up to 10 sublevels of categories!!

    (modified) example.htm
    Code:
    <HTML>
    
    <HEAD>
    <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <META name="GENERATOR" content="Microsoft FrontPage 4.0">
    <META name="ProgId" content="FrontPage.Editor.Document">
    <TITLE>HV Menu example</TITLE>
    </HEAD>
    
    <BODY>
    <span id="navbarheader"></span>
    <SCRIPT type='text/javascript'>
    
    //HV Menu- by Ger Versluis (http://www.burmees.nl/)
    //Submitted to Dynamic Drive (http://www.dynamicdrive.com)
    //Visit http://www.dynamicdrive.com for this script and more
    
    function Go(){return}
    
    </SCRIPT>
    <SCRIPT type='text/javascript' src='/scripts/jsdropdown.php'></SCRIPT>
    <SCRIPT type='text/javascript' src='/scripts/menu_com.js'></SCRIPT>
    <NOSCRIPT>Your browser does not support script</NOSCRIPT>
    </BODY>
    
    </HTML>
    I'm afraid i cant currently gice anyone links to see this live on the net, as we are working on it on a local machine.

    Once it gets uploaded (and hopefully fixed ) i'll post links for you all

    /me now prays for help, and i hope many other people are able to use this on their sites
    Last edited by tandyuk; 03-31-2006 at 05:54 PM.

  6. #6
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Important note: Two types of questions that we generally do NOT support
    Hi:
    To save everyone time, please note that the following two types of questions we generally will skip over when posted on the forums due to their time consuming nature:

    1) Questions regarding how to get multiple copies of the same script to work on the same page, or multiple, different scripts. The reasons for two scripts suddenly not working when put on the same page can be many, including duplication in the two scripts' variable names, functions, or access to an event handler etc. The only advise we can give is to try and remove the lesser important script(s) to see if that resolves the conflict.

    2) Questions on complex 3rd party scripts such as "HV Menu." Since we didn't write these scripts and due to their complexity, it's hard to provide support for them. Such questions can still be posted, though just bear in mind that in many cases, we cannot help you out. If you've discovered a bug with one of these scripts, you are encouraged to post them, however, so we can get in touch with the original author on fixing them.

    Thanks,

    If the creator of this script still reads these forums, please get in touch with me!
    I've tried all the email addresses i found, but none work

  7. #7
    Join Date
    Mar 2006
    Location
    Worthing, UK
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I've found a workaround!

    Ok, i can now get the navbar to display on the page, but its a bit iffy lol.

    Instead of calling the javascript on my page, instead i have a 1x8 pixel iframe (to pull the header background down to cover the menu), and the example page i edited called as the iframe source.

    The menu then loads, and i have navbar covering up the tiny iframe.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •