We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34959
    • 1 Posts
    ------------------------------
    functions.php
    ---------------------


    <?php
    // PROJECT RELATED FUNCTIONS
    class PHP_fun
    {
    function getConfig()
    {
    $this->DB_SERVER = ’localhost’;
    $this->DB_USER = ’root’;
    $this->DB_PASS = ’88’;
    $this->DB_NAME = ’db’;

    }

    function __construct()
    {
    $this->getConfig();
    $Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS);
    if (!$Conn)
    die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
    $DB_select = mysql_select_db($this->DB_NAME, $Conn);
    if (!$DB_select)
    die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
    }

    function select_row($sql)
    {
    //echo $sql . "
    ";
    if ($sql!="")
    {
    $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
    if ($result)
    {
    while($row = mysql_fetch_array($result))
    $data[] = $row;
    }
    return $data;
    }
    }

    function recordCount($sql)
    {
    if ($sql!="")
    {
    $result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
    if ($result)
    {
    $cnt = mysql_num_rows($result);
    return $cnt;
    }
    }
    }

    function createProductUrl($url)
    {
    $url = trim($url);
    if ($url != "")
    {
    $url = trim(str_replace(" ","-",$url));
    //return $url.".html";
    return $url;
    }
    }

    function getChild($categoriesid)
    {
    $menu = "";
    $str = "";

    $s = "select c.categories_id, cd.categories_name, c.parent_id from CATEGORIES c, CATEGORIES_DESCRIPTION cd where cd.language_id=’" . (int)$languages_id ."’ and c.parent_id = ’$categoriesid’";
    $res = $this->select_row($s);
    $menu .= ’<div c.categories_id="’.$categoriesid.’" style="display:none; position:absolute;" onmouseover="javascript: return showId(’.$categoriesid.’);" onmouseout="javascript: return hideId(’.$categoriesid.’);">’;
    $menu .= ’<table border="1" cellspacing="0" cellpadding="0" style="border: 1px solid #FDCB55; border-collapse:collapse;">’;
    for ($i=0;$i<count($res);$i++)
    {
    $cnt_of_child = $this->recordCount("select c.categories_id, cd.categories_name, c.parent_id from CATEGORIES c, CATEGORIES_DESCRIPTION cd where c.parent_id = ’" . (int)$value . "’ and cd.language_id=’" . (int)$languages_id ."’ ");
    if ($cnt_of_child > 0)
    $str = ’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="arrow_white.gif">’;
    else
    $str = " ";


    $menu .= ’<tr height="20"><td align="left" class="aerial12" onmouseover="this.className=\’aerial12over\’;return showId(’.$res[$i][categories_id].’);" onmouseout="this.className=\’aerial12\’;return hideId(’.$res[$i][categories_id].’);" style="cursor:pointer;">’;
    $menu .= ’<div style="padding-left:10px;padding-right:5px; width:125px;">’;


    $menu .= $res[$i][categories_name].$str;
    $menu .= ’</div>’;
    $menu .= ’</td><td align="left" valign="top">’;
    $menu .= $this->getChild($res[$i][categories_id]);
    $menu .= ’</td></tr>’;
    }
    $menu .= ’</table>’;
    $menu .= ’</div>’;
    return $menu;
    }

    function getMenu($parentid)
    {
    $menu = "";
    $s = "select c.categories_id,cd.categories_name,c.parent_id from categories c, categories_description cd where c.categories_id = cd.categories_id and c.parent_id = ’$parentid’";
    $res = $this->select_row($s);
    ob_start();
    ?>
    <table border="0" cellspacing="0" cellpadding="0" width="740" align="center">
    <tr height="30">

    <?php
    for ($i=0;$i<count($res);$i++)
    { ?>
    <td align="left" valign="middle" bgcolor="#FCBB2B">

    <div align="center" onmouseover="javascript: return showId(’<?=$res[$i][categoriesid]?>’);" onmouseout="javascript: return hideId(’<?=$res[$i][categoriesid]?>’);" class="aerial12" style="height:15px; vertical-align:middle; padding-top:5px;cursor:pointer;"><?=$res[$i][categories_name]?></div><?=$this->getChild($res[$i][categoriesid])?>

    </td>
    <?php if ((count($res) - 1) > $i) {?>
    <td align="left" valign="middle" bgcolor="#FCBB2B">|</td> <?php } ?>
    <?php } ?>
    </table>
    <?php
    $menu = ob_get_contents();
    ob_end_clean();
    return $menu;
    }
    }//class PHP_fun()
    ?>

    --------------------
    menu.php
    -----------------


    <?php
    require ’functions.php’;
    $db = new PHP_fun;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>PHP/MySQL/Javascript Multilevel Drop Down Menu</title>
    <script language="javascript">
    function redirect(url)
    {
    window.open(url) ;
    return false;
    }
    function showId(categoriesid)
    {
    var obj = document.getElementById(categoriesid);
    obj.style.display = ’block’;
    return false;
    }
    function hideId(categoriesid)
    {
    var obj = document.getElementById(categoriesid);
    obj.style.display = ’none’;
    return false;
    }
    </script>
    <style type="text/css">
    <!--
    body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    .aerial12
    {
    font-family:Verdana;
    font-size:9px;
    font-weight:bold;
    text-decoration:none;
    color:#402903;
    background-color:#FCBB2B;
    text-transform:uppercase;
    }

    .aerial12over
    {
    font-family:Verdana;
    font-size:9px;
    font-weight:bold;
    text-decoration:none;
    color:#402903;
    background-color:#FDCB55;
    text-transform:uppercase;
    }

    -->
    </style>

    </head>
    <body>
    <table width="776" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <td align="center" valign="top">&nbsp;</td>
    </tr>
    <tr>
    <td align="center" valign="top" height="100"><?=$db->getMenu(0);?></td>
    </tr>
    </table>
    </body>
    </html>

    i want make dynamic dropdown menu using mysql and php. here is my coding and related tables. i can view main categories , but my problem is when mouse over to main category , it didn’t show sub categories. check these codings and help me please.
      • 4310
      • 2,310 Posts
      [!Wayfinder!]
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Yeah, the functions.php and the method you’ve outlined above is much more a "do-it-yourself" way of approaching it, which is not necessary! You’re doing more work than you need to! Just use the Wayfinder Snippet to create menus -- it is extremely flexible.