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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Just wondering if there is an easier way?

    Hello,

    I am currently building a navigation menu for my site. I plan on using twitter bootstrap to do so and would like to use jQuery to the html output as desired.

    I am already querying all the information needed from my database using php and I have it set as variables for another area of the site, so what I'm doing is just json encoding those arrays and then will be using the jQuery to manipulate the data. There will be both categories and subcategories so I'm pulling in two different php arrays.

    I know this can be done in PHP in much of the same manner, but you can't learn if you don't do. So I'm just wondering if there is an easier way to get this done or if I should probably just stick to using php for this.

    Sorry if my code is a little messy and I know it's not commented out like it should be.

    Thanks for any advice.

    Code:
    <script type="text/javascript">
             $(document).ready(function() 
             {
                var categoryArray = <?php echo json_encode($menu); ?>;   
                var subcategoryArray = <?php echo json_encode($subcategories); ?>;
                         
                for(i=0; i < categoryArray.length; i++)
             {
                    console.log(categoryArray[i]['Category']['name']);
    
                    for(j=0; j < subcategoryArray.length; j++ )
                    {
                              if(subcategoryArray[j]['Category']['id'] === categoryArray[i]['Category']['id'])
                              {
                                console.log(subcategoryArray[j]['Subcategory']['name']);
                              }
                        }       
                    }
        });
         </script>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,180
    Thanks
    23
    Thanked 603 Times in 602 Posts
    Why would you need the database to write a menu? Does it change for every page? The easiest way to write a menu is to hand code it in HTML.
    Unless you have something strange going on.

    Study this example:
    http://jsfprimefacesblog.blogspot.co...down-menu.html
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 2 Times in 2 Posts
    It's going to be dynamically created from an admin back-end. I am creating myself a custom CMS system for myself and the company I am currently developing.

    The main reason I am needing a dynamic menu area is because there will be a lot of categories/subcategories inside the menu. Instead of hard coding a menu that I will have to change every time I add in a subcategory, it's much easier and nicer to log into a back-end and simply give it a name and a parent category. It will save hours of work in the long run which is important when it's just you running the application.

    One thing I've learned is if you can make it dynamic you should. It may take a little extra set up in the beginning but once things get going and you're having to add content on a regular basis it will save you time and make your job a lot easier.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,180
    Thanks
    23
    Thanked 603 Times in 602 Posts
    No problem valandor062. I have never worked on anything that needed that much for a menu. I see that you did get your js method though. I'll have to look into shtml(was that it? - I'll go see.)
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    New to the CF scene
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I do appreciate the response sunfighter, and being part of a community means asking questions.

    I don't mean to sound like I'm a jerk or anything in my responses... I know I don't have good people skills... Usually I do hard code small menus when building web pages, or use WordPress and it does most of everything for me and what it doesn't, I make it do it anyway.

    In my current project I will have 10+ categories all of with will have 7-10 sub-categories to display. This will change over time as members request new categories and/or subcategories and the ones that seem to be dead I'll be removing.

    While time will only tell how successful the over concept of the application will work, I am hoping to be able to make things quick and easy for me right from the start and make everything I can dynamic so all I would truly have to worry about is design elements and not coding new things into the back-end.

    Thank you again sunfighter, I truly appreciate anyone who spends their time to help others. These fourms are built on peoples willingness to help, and you've been here helping people for a long time when you very would don't have to be.


  •  

    Posting Permissions

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