SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Howdy folks! I'm fairly new to PHP/MySQL, and I'm very stuck with a not-so-simple problem. I realize that this is a huge problem, and you may not want to help me, due to the fact that it is so big, but I would not be posting a problem of this magnitude if I hadn't worked on it for several days, without figuring out how to do. Okay, here goes:

    I want to use a JavaScript menu for my website. This is how the menu contents are generated:

    Code:
    //MAIN 0
    
    //Main items:
    // makeMain(MAIN_NUM,'TEXT','LINK','FRAME_TARGET') (set link to 0 if you want submenus of this menu item)
    oMenu.makeMain(0,'Dynamic HTML',0)
            //Sub items:
            // makeSub(MAIN_NUM,SUB_NUM,'TEXT','LINK',TOTAL,'FRAME_TARGET') (set link to 0 if you want submenus of this menu item)
            oMenu.makeSub(0,0,'Scripts',0,5)
            oMenu.makeSub(0,1,'Demos',0,5)
            oMenu.makeSub(0,2,'Support',0,5)
            oMenu.makeSub(0,3,'Tutorials',0,5)
            oMenu.makeSub(0,4,'Forums',0,5)
                    //SubSub items:
                    // makeSubSub(MAIN_NUM,SUB_NUM,SUBSUB_NUM,'TEXT','LINK',TOTAL,'FRAME_TARGET')
                    oMenu.makeSubSub(0,0,0,'ZoomFade',0,7)
                    oMenu.makeSubSub(0,0,1,'ScrollText',0,7)
                    oMenu.makeSubSub(0,0,2,'PageScroll','#',7)
                    oMenu.makeSubSub(0,0,3,'Foldoutmenu','#',7)
                    oMenu.makeSubSub(0,0,4,'Spotlight','#',7)
                    oMenu.makeSubSub(0,0,5,'Bgchange',0,7)
                    oMenu.makeSubSub(0,0,6,'Showhide','#',7)
    
                            //** NEW **
                            //SubSubSub items:
                            // makeSubSub2(MAIN_NUM,SUB_NUM,SUBSUB_NUM,SUBSUBSUB_NUM,'TEXT','LINK',TOTAL,'FRAME_TARGET')
                            oMenu.makeSubSub2(0,0,0,0,'Scripting',0,2)
                            oMenu.makeSubSub2(0,0,0,1,'test2','#',2)
    
                            oMenu.makeSubSub2(0,0,1,0,'test3','#',3)
                            oMenu.makeSubSub2(0,0,1,1,'test4','#',3)
                            oMenu.makeSubSub2(0,0,1,2,'test5','#',3)
    
                            oMenu.makeSubSub2(0,0,5,0,'Google','http://www.google.com/',5)
                            oMenu.makeSubSub2(0,0,5,1,'Fast Search','http://www.alltheweb.com/',5)
                            oMenu.makeSubSub2(0,0,5,2,'AltaVista','http://www.altavista.com/',5)
                            oMenu.makeSubSub2(0,0,5,3,'HotBot','http://www.hotbot.com/',5)
                            oMenu.makeSubSub2(0,0,5,4,'Lycos','http://www.lycos.com/',5);
                                    //** NEW **
                                    //SubSubSubSub items:
                                    // makeSubSub3(MAIN_NUM,SUB_NUM,SUBSUB_NUM,SUBSUBSUB_NUM,SUBSUBSUBSUB_NUM,'TEXT','LINK',TOTAL,'FRAME_TARGET')
                                    oMenu.makeSubSub3(0,0,0,0,0,'Bratta Forum','http://www.bratta.com/dhtml/forum/default.asp',5)
                                    oMenu.makeSubSub3(0,0,0,0,1,'Bratta dot Com','http://www.bratta.com/',5)
                                    oMenu.makeSubSub3(0,0,0,0,2,'Bratta Scriptomania','http://www.bratta.com/dhtml/scripts.asp',5)
                                    oMenu.makeSubSub3(0,0,0,0,3,'Doc Javascript','http://www.webreference.com/js/',5)
                                    oMenu.makeSubSub3(0,0,0,0,4,'Dynamic Duo','http://www.dansteinman.com/dynduo/',5)
    
                    oMenu.makeSubSub(0,1,0,'DHTML Guestbook',0,6)
                    oMenu.makeSubSub(0,1,1,'DHTML Intro',0,6)
                    oMenu.makeSubSub(0,1,2,'CircleMenu','#',6)
                    oMenu.makeSubSub(0,1,3,'DHTML Space 1.0','#',6)
                    oMenu.makeSubSub(0,1,4,'Old site 4','#',6)
                    oMenu.makeSubSub(0,1,5,'BallControl','#',6)
                            oMenu.makeSubSub2(0,1,0,0,'The Register','http://www.theregister.co.uk/',3)
                            oMenu.makeSubSub2(0,1,0,1,'Wired News','http://www.wired.com/',3)
                            oMenu.makeSubSub2(0,1,0,2,'Need to Know','http://www.ntk.net/',3)
    
                            oMenu.makeSubSub2(0,1,1,0,'Asahi Shimbun','http://www.asahi.com/english/enews/enews.html',4)
                            oMenu.makeSubSub2(0,1,1,1,'BBC Online','http://www.bbc.co.uk/home/today/',4)
                            oMenu.makeSubSub2(0,1,1,2,'New Stateman','http://www.newstatesman.co.uk/',4)
                            oMenu.makeSubSub2(0,1,1,3,'SF Examiner','http://examiner.com/',4)
    
                    oMenu.makeSubSub(0,2,0,'Site FAQ','#',2)
                    oMenu.makeSubSub(0,2,1,'Scripts FAQ','#',2)
                            oMenu.makeSubSub2(0,2,1,0,'test','#',2)
                            oMenu.makeSubSub2(0,2,1,1,'test','#',2)
    
                    oMenu.makeSubSub(0,3,0,'Introduction','#',3)
                    oMenu.makeSubSub(0,3,1,'5th generation','#',3)
                    oMenu.makeSubSub(0,3,2,'Keyboard','#',3)
    
                    oMenu.makeSubSub(0,4,0,'Forum 1','test.html',2)
                    oMenu.makeSubSub(0,4,1,'Forum 2','test.html',2)
    
    //MAIN 1
    oMenu.makeMain(1,'Help',0)
            oMenu.makeSub(1,0,'How do I do this?',0,3)
            oMenu.makeSub(1,1,'How? (no submenu)',0,3)
            oMenu.makeSub(1,2,'Why does it work?',0,3)
                    oMenu.makeSubSub(1,0,0,'Like this part 1',0,3)
                    oMenu.makeSubSub(1,0,1,'Like this part 2','test.html',3)
                    oMenu.makeSubSub(1,0,2,'Like this part 3',0,3)
                            oMenu.makeSubSub2(1,0,0,0,'Reading',0,5)
                            oMenu.makeSubSub2(1,0,0,1,'Slashdot','http://www.slashdot.com/',5)
                            oMenu.makeSubSub2(1,0,0,2,'Salon','http://www.salon.com/',5)
                            oMenu.makeSubSub2(1,0,0,3,'WebReference','http://www.webreference.com/',5)
                            oMenu.makeSubSub2(1,0,0,4,'GlassDog','http://www.glassdog.com/',5)
                                    oMenu.makeSubSub3(1,0,0,0,0,'ObscureStore','http://www.obscurestore.com/',4)
                                    oMenu.makeSubSub3(1,0,0,0,1,'Tom Paine','http://www.tompaine.com/',4)
                                    oMenu.makeSubSub3(1,0,0,0,2,'Slate','http://www.slate.com/',4)
                                    oMenu.makeSubSub3(1,0,0,0,3,'The Bleat','http://www.lileks.com/bleats/index.html',4)
    
                    oMenu.makeSubSub(1,2,0,'Forum 1','test.html',2)
                    oMenu.makeSubSub(1,2,1,'Forum 2','#',2)
                            oMenu.makeSubSub2(1,2,1,0,'test3','#',3)
                            oMenu.makeSubSub2(1,2,1,1,'test4','#',3)
                            oMenu.makeSubSub2(1,2,1,2,'test5','#',3)
    How, I want this menu to be generated dynamically, pulling the menu items from a database. There are a few problems with this:
    1. The menu must be in the above format
    i.e. for each submenu - the items must be numbered in order 0-1-2-3-4-5->. Any other order screws up the script. This poses a problem due to the fact that pulled arrays is NOT in this order. Since some get sorted out, due to that some subcategories doe not exist in the main category etc.) The array usually goes like 1-4-7-9->...

    2. The database pulling
    The menu goes like this:
    Main > Categories > Topics > Articles

    The sub menu (directly under the main item) which are the categories and can be pulled directly from the category database. No problems here.

    The subsub menus, which are the topics, must be generated by selecting ONLY the topics which is attached to the parent category.

    And the subsubsub menus, which are the articles, must thus be pulled from the database selecting only the topics which has the parents category and topic.


    I have tried doing this with WHILE loops withing other WHILE loops, but I can't get it to work. Please help an individual who wants to be a code poet someday.

    You can find the menu script here, if you like to have a closer look:
    http://www.bratta.com/dhtml/scripts/scripts.asp?id=28
    Last edited by M. Johansson; Feb 22, 2001 at 11:56.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm - this is a tuffy. I just downloaded the code for cool menus. First thing - before worrying about the PHP/mySQL and getting the data into your javascript/html - perhaps you should read over the documentation for cool scipts another time.

    Because, none of these functions belong to the object oMenu. You are calling functions that don't exist!
    Code:
    oMenu.makeSubSub2(1,0,0,0,'Reading',0,5) 
    oMenu.makeSubSub2(1,0,0,1,'Slashdot','http://www.slashdot.com/',5) 
    oMenu.makeSubSub2(1,0,0,2,'Salon','http://www.salon.com/',5) 
    oMenu.makeSubSub2(1,0,0,3,'WebReference','http://www.webreference.com/',5) 
    oMenu.makeSubSub2(1,0,0,4,'GlassDog','http://www.glassdog.com/',5) 
    oMenu.makeSubSub3(1,0,0,0,0,'ObscureStore','http://www.obscurestore.com/',4) 
    oMenu.makeSubSub3(1,0,0,0,1,'Tom Paine','http://www.tompaine.com/',4) 
    oMenu.makeSubSub3(1,0,0,0,2,'Slate','http://www.slate.com/',4) 
    oMenu.makeSubSub3(1,0,0,0,3,'The Bleat','http://www.lileks.com/bleats/index.html',4)
    From reading through the file coolmenus.js there are three tiers of menu you can create with the class menObj :
    function makeMain(num,text,link,target)
    function makeSub(num,subnum,text,link,total,target)
    function makeSubSub(num,subnum,subsubnum,text,link,total,target)

    so you can call
    oMenu.makeMain(num,text,link,target)
    oMenu.makeMain(num,text,link,target)
    oMenu.makeSubSub(num,subnum,subsubnum,text,link,total,target)

    Anyway, object oriented javascript is completely new to me. Looks cool though! So I'll keep reading.

    PS. To preserve the formating of your code enclose it in "["code"]" "["/code"]" tags when posting. Next time you post - on the page with the form that you type your post into click onto the vB_code link for more info.
    Last edited by freakysid; Feb 22, 2001 at 10:36.

  3. #3
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oh darn, I forgot to mention that I'm using a modified version of the script to generate the extra subsub2 and subsub3 function. So it's in order, even though it does not look like it at first glance.

    http://www.bratta.com/dhtml/howtos/c...ifications.asp (see "extra submenus") the script is essentially the same, though.

    Let me also clarify that the problem is not the javascript the javascript works fine. The problem is how to generate the above codeblock correctly using PHP/MySQL - that's what I need help for - so if you know PHP, I can use your help.
    Last edited by M. Johansson; Feb 22, 2001 at 12:09.

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    truelight,

    This problem could be solved with a recursive function that loops through your menu list with a counter for each level. Here's some rought pseudocode to give you the idea, but it will take some work (I've ignored the fact that the root menu uses makeMain() instead of makeSub(), for example) and will depend a lot on how you store the information in the database:

    PHP Code:
    function makeMenu($menuid,$parents) {
      if (
    $menuid="") {
        
    // get the root menu items
      
    } else {
        
    // get the menu items that are children of $menuid
      
    }

      for (
    $menuindex=0;$menuindex<count($menuitems);$menuindex++) {
        echo(
    "oMenu.makeSub(");
        foreach (
    $parents as $parent) echo("$parent,");
        echo(
    "'link name here',");
        if (
    has sub-menu items) echo("0,");
        else echo(
    "'link URL here',");
        echo(
    count($menuitems).");");

        
    $tempparents $parents;
        
    $tempparents[] = $menuindex;
        
    makeMenu($thismenuid,$tempparents);
      }

    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I've got it working now, using 4 million WHILE loops. It's crude, but works well. Thanks anyway - I'll keep your script example for safekeeping, in case my host threatens me with bodily harm for bogging down the server.


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
  •