SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Editing a javascript operated menu using MySql and PHP

    I have created a javascript operated menu in Fireworks. Am wondering if there would be a way of editing the menu below using MySql and PHP? I am wanting to display certain links in the menu. The links should be coming from a mysql database and using php to display those links. I need to determine which link goes where. For instance about button should contact us, etc for a menu and gp services button should have library, etc for a menu. Can someone please help me with this as I am stuck? Thanks in advance.
    Code JavaScript:
    function mmLoadMenus() {
      if (window.mm_menu_0707185109_0) return;
      window.mm_menu_0707185109_0 = new Menu("root",142,20,"Verdana, Arial, Helvetica, sans-serif",10,"#ffffff","#ffffff","#00397a","#0046c2","left","middle",3,0,1000,-5,7,true,false,true,0,true,true);
      mm_menu_0707185109_0.addMenuItem("BDGP BOARD","location='page.php?page=BDGP+Board'");
      mm_menu_0707185109_0.addMenuItem("BDGP OBJECTIVES","location='page.php?page=BDGP+Objectives'");
      mm_menu_0707185109_0.addMenuItem("REGIONAL ACTIVITIES","location='page.php?page=Regional+Activities'");
      mm_menu_0707185109_0.addMenuItem("CONTACT US","location='page.php?page=Contact+Us'");
       mm_menu_0707185109_0.hideOnMouseOut=true;
       mm_menu_0707185109_0.menuBorder=0;
       mm_menu_0707185109_0.menuItemBorder=0;
       mm_menu_0707185109_0.menuLiteBgColor='#ffffff';
       mm_menu_0707185109_0.menuBorderBgColor='#555555';
       mm_menu_0707185109_0.bgColor='#555555';
    mm_menu_0707185109_0.writeMenus();
    } // mmLoadMenus()

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    PHP can quite happily generate variables that can be used in Javascript,

    consider the following:
    PHP Code:
    <?php

    $myMessage 
    'MESSAGE';
    echo 
    '<script type="text/javascript">';
    echo 
    'alert(\''$myMessage .'\')';
    echo 
    '</script>';

    ?>
    Poor example but it gives the principle!

    If you use php to echo the script, you an use the results from the database to populate the menu with the results variables.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that spikeZ.

    How do I keep this number 0707185109_0 incrementing for each menu that is created?

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Taking the above code as an example:
    PHP Code:
    $i=0;
    while(
    $rows=mysql_fetch_assoc($sql)) {
    $menu_id 'mm_menu_0707185109_0'.$i;
    echo 
    '    
    function mmLoadMenus() {
      if (window.'
    .$menu_id.') return;
      window.'
    .$menu_id.' = new Menu("root",142,20,"Verdana, Arial, Helvetica, sans-serif",10,"#ffffff","#ffffff","#00397a","#0046c2","left","middle",3,0,1000,-5,7,true,false,true,0,true,true);
          '
    .$menu_id.'.addMenuItem("BDGP&nbsp;BOARD","location=\'page.php?page=BDGP+Board\'");
          '
    .$menu_id.'.addMenuItem("BDGP&nbsp;OBJECTIVES","location=\'page.php?page=BDGP+Objectives\'");
          '
    .$menu_id.'.addMenuItem("REGIONAL&nbsp;ACTIVITIES","location=\'page.php?page=Regional+Activities\'");
          '
    .$menu_id.'.addMenuItem("CONTACT&nbsp;US","location=\'page.php?page=Contact+Us\'");
           '
    .$menu_id.'.hideOnMouseOut=true;
           '
    .$menu_id.'.menuBorder=0;
           '
    .$menu_id.'.menuItemBorder=0;
           '
    .$menu_id.'.menuLiteBgColor=\'#ffffff\';
        '
    .$menu_id.'.menuBorderBgColor=\'#555555\';
        '
    .$menu_id.'.bgColor=\'#555555\';
        '
    .$menu_id.'.writeMenus();
    } // mmLoadMenus()
    '
    ;
    $i++; // add 1 on each loop

    Obviously you will need to alter it to suit your needs
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist cturner01's Avatar
    Join Date
    Jun 2006
    Location
    My computer
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you spikeZ.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    No problem
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •