Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic menu item creation for "Tigra" (DHTML) menu. HELP!

    I have a freeware product called "Tigra menu" in use as javascript/DHTML dropdown menu engine. Tigra Menu homepage

    The menu items will be populated from the database (MySQL), and the table structure I use, is so called "Modified Preorder Tree Traversal", more info here

    And the PHP code I've made for generating javascript menu item file (more info here) is:

    PHP Code:
    <?php

    header
    ("content-type: text/plain");
    mysql_connect (MYSQL_HOSTMYSQL_USERMYSQL_PASSWD) or die("Database error 1");
    mysql_select_db (MYSQL_DATABASE) or die("Database error 2");

    echo 
    'var MENU_ITEMS = ['."\n";

    $right = array(); 

    $sql "
    SELECT `id`, `menutext`, `lft`, `rgt`, `parent`, `active`, `hide_in_menus`
    FROM `structure` 
    ORDER BY `lft` ASC"
    ;

    $res mysql_query($sql);
    $rows mysql_num_rows($res);

    while (
    $row mysql_fetch_array($res)) { 
        
    $i++;
        if (
    count($right) > 0) { 
            while (
    $right[count($right) - 1] < $row[rgt]) { 
                
    array_pop($right); 
            }
        }

        if (
    $row[parent] != && $row[active] == && $row[hide_in_menus] != 1) {
            
    $url 'main.php?page='.$row[id];

            if (
    count_childs($row[lft], $row[rgt]) >= 1) {                
                
    // Has one or more child nodes
                
    $link "['".($row['menutext'])."', '".$url."', null,\n";
                
    $open 1;
            } else {            
                
    // Zero child nodes
                
    $link =    "['".($row['menutext'])."', '".$url."'],\n";
            }

            if (
    count($right) < $prev_count) {                
                
    $open 0;
                echo 
    str_repeat(str_repeat(' ', (count($right) * 4))."],\n\n", ($prev_count count($right)));
            }

            echo 
    str_repeat(' ', (count($right) * 4)).$link;
        }
        
    $prev_count count($right);
        
    $right[] = $row[rgt];


    if (
    $i >= $rows) { 
        if (
    $open == 1) {
            echo 
    "],\n";
        }
    }
    echo 
    "
    ];
    "
    ;

    // Counts the amount of the child nodes
    function count_childs($left$right) {
        return ((
    $right $left 1) / 2);
    }

    ?>
    And what is the problem?
    This PHP script is working pretty good, but in some cases it generates invalid javascript code, so the Tigra menu won't populate the menu.

    Why?
    Mostly because I need the hide_in_menus -feature (it's an integer field in the database) so I can hide the menu items I want from the structure.Everywhere in the tree: from the begin, from middle, and from the end.

    In some cases, if I left the menu item out of printing (hide in menus == 1), the generated javascript code looks like:
    Code:
    ['item under this is hidden (let out of printing)', null, null,
    
    ],
    ['Another', null, null,
        ['Level 1 Item 0', 'another.html'],
        ['Level 1 Item 1'],
        ['Level 1 Item 2'],
        ['Level 1 Item 3'],
    ],
    ...when this SHOULD BE:
    Code:
    ['item under this is hidden (let out of printing)', null, null],
    ['Another', null, null,
        ['Level 1 Item 0', 'another.html'],
        ['Level 1 Item 1'],
        ['Level 1 Item 2'],
        ['Level 1 Item 3'],
    ],
    So as you can see, there's a tag that stays open, even it contains no visible items. It needs line
    Code:
    ['item under this is hidden (let out of printing)', null, null],
    INSTEAD OF
    Code:
    ['item under this is hidden (let out of printing)', null, null,
    
    ],
    if there are NO visible ($hide_in_menus == 0) items inside it.

    I know this sounds like very complex and hard to understand what I mean, but I have no ideas anymore how to solve this problem. Without this "hiding" feature everything works fine (becouse the count_childs() -function will give a correct result everytime), but I just need that feature.

    If anyone can help me to modify the code, or give me ideas (or complete script) to create smarter way to generate Tigra menu items from the "Modified Preorder Tree Traversal" -page structure, I'll be very grateful!

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Welcome to the Coding Forums, qin3!

    I don't want to sound like I'm trying to get rid of you, especially since this is your first post here, but have you tried the Tigra forums? The reason I suggest going there is that you'd probably have a better chance of getting your questions answered, since people on that forum are familiar with your software. If you haven't already done so, you might want to use their forum search to see if anyone has run into a similar issue to yours.

    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Posting Permissions

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