Current location: Hot Scripts Forums » Programming Languages » PHP » Dynamic menu item creation for "Tigra" (DHTML) menu. HELP!


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

Reply
  #1 (permalink)  
Old 02-10-06, 08:38 AM
qin1 qin1 is offline
New Member
 
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!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Dynamic Menu matt001 ASP.NET 2 01-06-06 04:19 PM
CSS, Xoops, DHTML menu.. need your help billyvision CSS 0 08-11-05 08:05 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Wow, a dynamic menu, error! Programme PHP 3 01-05-04 02:16 PM


All times are GMT -5. The time now is 06:33 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.