#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    29
    Rep Power
    0

    Smile Building DHTML menu with PHP


    Hi!

    I'm trying to build a script that makes it possible to generate a dhtml navigation menu. The plan is to distinguish several levels of hierarchy (using the output of a database), in this case three: category, product, item.
    Realising a complete exposition will distract you from further reading, I simply would like to ask for some idea's how to do this.
    An example of the appearence of the menu can be found at www.samsung.nl (difference: no images are to be used).
    Thanks!

    Max
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    15
    If you're able to write the DHTML you're pretty much there. All you need to do is see which entities repeat, what data is variable, and what you need to extract with PHP. Then it's simply a matter of echoing the right data.
    --
    Regards
    André Nęss

    Puritanism: The haunting fear that someone, somewhere may be having fun
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    29
    Rep Power
    0
    I've got not too much experience with DHTML, but the technique, used at www.samsung.nl, is not very difficult. Problem for me is to write a script, that, regardless the number of levels in the menu, can automate the process of making the menu.
    Although not al the comments are translated from dutch, here you find the first lines of my script:
    PHP Code:
    <?
    require("connect.php");

    // MenuBuilder. Twee versies: IE4+ en anders --> I specify a browsercheck

    $browserinfo explode(";",$HTTP_USER_AGENT);
    if((
    substr($browserinfo[1],1,4) == "MSIE")&&(substr($browserinfo[1],6,3) >= 4))
     { 

    // IE4+ menu
    // Variabelen instellen --> coming section is declaring some variables

    $bgcolor     "#888888";
    $bgcolordir  "#aaaaaa"//Als er nog resultaten op lager niveau achterzitten
    $borderstyle "solid";
    $borderwidth "1px";
    $bordercolor "#000000";
    $bgtextcolor "#ffff99";
    $textcolor   "#000000";
    $fontsize    "9px";
    $fontfamily  "helvetica, verdana, arial";
    $menubreedte "120px";

    // Afhankelijk van het aantal niveaus subpag's instellen (doelgroepen achterwege gelaten => eerst dynamisch deel werkende krijgen)
    $subpag         = array("$dir_pagina/categorie.php3?ID=","$dir_pagina/product.php3?ID=","$dir_pagina/item.php3?ID="); //hoogste niveau eerst (=> means: highest level first)

    // Afhankelijk van het aantal niveaus de tabelnamen specificeren
    $sub         = array("categorie","product","item"); //hoogste niveau eerst

    // Bepaal de koppeling tussen categorieėn. Eerste is altijd leeg. => here the ID's how to relate the levels to each other are specified
    $koppeling   = array("","CatID","ProductID");

    // Bepaal wat te laten zien voor de listing => fieldnames for displaying in the menu are specified
    $show        = array("CatNaam","ProductNaam","ItemNaam");

    // Bepaal de naam van de IDvariabelen
    $idvar         = array("CatID","ProductID","ItemID");

    // Aantal niveaus => count the number of levels
    $aantal_niveaus count($sub);

    // Niveaus opbouwen
    $datasub  = array();
    $countsub = array();

    for(
    $i=0$i<$aantal_niveaus$i++)
     {
      echo 
    "niveau $i <br>";
      echo 
    $show[$i]."<br>";
      
      
    // resetten
      
    $query_ext "";

      if(
    $i!=0)
         {
          
    $query_ext "WHERE $koppeling[$i] = ??";
         }

      
    $datasub[$i]    = mysql_query("SELECT * FROM $sub[$i] $query_ext");
      
    $countsub[$i]   = mysql_num_rows($datasub[$i]);
        for(
    $p=0$p<$countsub[$i]; $p++)
       {
           
    $rij mysql_fetch_object($datasub[$i]);         
      echo 
    $rij->$show[$i];
      echo 
    $rij->$idvar[$i];"<br>";

    //
    // Here is where I ended...it's a mess!
    // How to do this?
    //

       
    }
     }

    // einde menubuilder
     
    }
     else
     {
    // Alternatief menu
     
    }

    I hope you know a better way doing this. I start making level one, but the next levels...they will be the problem.
    Thanks.

    Max

IMN logo majestic logo threadwatch logo seochat tools logo