Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:54

how to use milonic with php/mysql


Poster: toxic
Dated: Friday September 22 2006 - 13:03:56 BST

how to use milonic with php/mysql

is there exist any phpscript that i can use with milonic?


Poster: toxic
Dated: Friday September 22 2006 - 15:39:20 BST

never mind, i fixed it, it works great


Poster: street9009
Dated: Wednesday September 27 2006 - 15:48:38 BST

Mind sharing with us how that's done? I'm trying to find out myself.


Poster: John
Dated: Wednesday September 27 2006 - 23:01:16 BST

You can put your php-type URLs, etc., within the aI statements. Then simply change the suffix on your menu_data.js file to menu_data.php.

Simplistic description, perhaps, but it should get you started.


Poster: Andy
Dated: Wednesday September 27 2006 - 23:36:12 BST

Hi,

There is a PHP sample as part of the menu download. Have a look in the extras folder.

Regards,
Andy


Poster: street9009
Dated: Sunday October 1 2006 - 20:00:26 BST

What if this is a MySQL database that you don't have any control over (refering to its structure)? I'm going to have to design some kind of algorithm to create the tree, but how to get that into the menu I'm just not sure.


Poster: PeteTheBloke
Dated: Tuesday October 3 2006 - 14:52:13 BST

I haven't done it myself, but it looks to me as if you can use Milonic without MySQL by going to extras/php_based_menu/tablebasedphpmenu.php

I'm trying to find out if the config opportunities are seriously limited when using PHP because the 'menu_data.js' file seems to be by-passed and the database doesn't have all the same fields. Anyone know? To save me hacking my way through the code.

Pete


Poster: kevin3442
Dated: Tuesday October 3 2006 - 16:14:18 BST

If I understand your meaning correctly... Yes, you can generate the menu through php without relying on a database. Generating the js code dynamically, using PHP, vs. using static js code should not affect your config options. Note thath the menu on the main Milonic.com site uses php, and it takes advantage of many of the config options.

Cheers,

Kevin


Poster: street9009
Dated: Wednesday October 4 2006 - 4:36:31 BST

Maybe this will help someone help me figure this out, I'm not sure.

But the structure of the table I need to build the menus from is as follows (well, the important parts, anyway):

categoryID name parent

Basically the categoryID will always be a link, even if it is a category with subcategories. 1 is the root. So all links with a parent of 1 would be shown initially, then any links with parents of those root links would be submenus, etc.

Does that make sense? Can anyone help me implement this?


Poster: street9009
Dated: Monday October 9 2006 - 22:22:09 BST

Anyone? I'm still having trouble understanding how the menus work with databases...


Poster: John
Dated: Monday October 9 2006 - 23:13:38 BST

Did you go over the complete example included in the download as Andy suggested?


Poster: street9009
Dated: Tuesday October 10 2006 - 2:36:23 BST

I have looked through every file in the php_mysql_based_menu folder and am still no closer to understanding how they work and definitely no closer to how I can modify them to work with the table structure above.


Poster: Andy
Dated: Friday October 20 2006 - 17:04:40 BST

Quote:
Can anyone help me implement this?


If you send over some sample data I'll see if we can create some sort of substitute field names so that you can use your field names with the database driven menu.

-- Andy


Poster: street9009
Dated: Friday October 20 2006 - 18:15:04 BST

Andy wrote:
Quote:
Can anyone help me implement this?


If you send over some sample data I'll see if we can create some sort of substitute field names so that you can use your field names with the database driven menu.

-- Andy


Funny that you post here. I was about to log in and post the solution I came up with. What I did was write a PHP script that converts the database structure above to the milonic database. It really wasn't too hard to do. If anyone ever tries to implement milonic in shop script again, I'd be happy to help with the conversion process.

Thanks for the offer though, Andy. This forum really is helpful. It's appreciated.


Poster: Ruth
Dated: Friday October 20 2006 - 18:21:09 BST

Hi,

Go ahead a post, we'd love it. Any solution to any issue is always welcome :)

Ruth

PHP Menu Disappearing


Poster: cooldudefx
Dated: Tuesday October 24 2006 - 5:09:56 BST

First off, thanks to all of you who have knowledge of this forum and menu. I have been through all of the articles I could find, but I cannot seem to find a solution. My website is at http://www.cojcl.com/index.php?pagename=home. I have inserted the code and all of the files, but the menu will not display. I have tried removing it from both the div tag and the table tag. Thanks to you all in advance.

cooldudefx,

CoJCL webmaster

EDIT: It would seem that I forgot to include the files before I inserted the PHP script. It works now.


Poster: street9009
Dated: Tuesday October 24 2006 - 22:08:59 BST

Code:
<?php
//October 13, 2006

//Variables for connections
global $milionic_connection;
global $ss_connection;


//Function to establish a connection to the Milonic menu database
function connectToMilonic()
{
   global $milionic_connection;
   //Connect to the milonic server
   $milionic_connection = mysql_connect ("servername", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());

   //select the milionic database
   mysql_select_db ("milonic_database");

}

//Function to terminate the connection to the milonic database
function closeMilonic()
{
   //Close the MySQL connection
   global $milionic_connection;
   mysql_close($milionic_connection);
}

//Function to establish a connection to the shop script database
function connectToShopScript()
{
   global $ss_connection;
   //connect to the shop script server
   $ss_connection=mysql_connect ("servername", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());

   //select the shop script database
   mysql_select_db("database");
}

//Function to terminate the connection to the shop script database
function closeShopScript()
{
   //Close the MySQL connection
   global $ss_connection;
   mysql_close($ss_connection);
}

//Function to build the menu tree for the passed in category ID
//Note: when this function is called, connection is to milonic DB
function buildMenuTree($ssMenuRowsResult, $name, $menuID, $categoryID)
{
   while ($array = mysql_fetch_array($ssMenuRowsResult))
   {
      $SSCategoryID = $array['categoryID'];
      $SSName   = $array['name'];
      
      closeMilonic();
      connectToShopScript();
      
      $query = "SELECT * FROM SS_categories WHERE parent = '$SSCategoryID'";
      $result = mysql_query($query);
      
      closeShopScript();
      connectToMilonic();
      
      //If there are no subcategories of the current category
      if (mysql_num_rows($result) == 0)
      {
         //Formulate the URL for the menu_item
         $url = "index.php?categoryID=";
         $url .= $SSCategoryID;
         
         //Insert the current category into the milonic database as an item
         $query = "INSERT INTO mm_items SET menuid = '$menuID',text = '$SSName', url='$url'";
         $insertResult = mysql_query($query);
      }
      else   //There are subitems, so need a menu and a menuitem
      {
         //Insert the current category into the milonic database as a menu
         $insert = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='$SSName'";
         $insertResult = mysql_query($insert);
         
         $newMenuID = mysql_insert_id();
         
         //Formulate the URL
         $url = "index.php?categoryID=";
         $url .= $SSCategoryID;
         
         //Insert the current category into the milonic database as an item
         $query = "INSERT INTO mm_items SET menuid = '$menuID',text = '$SSName', url='$url', showmenu='$SSName'";
         $insertResult = mysql_query($query);
         

                        //For each subitem, build a menu tree for it (recursive call)
         while ($line = mysql_fetch_array($result))
         {
            $newName = $line['name'];
            $newCategoryID = $line['categoryID'];
         
            buildMenuTree($result, $newName, $newMenuID, $newCategoryID);
         }
      }
   }
}

//Connect to the Milonic DB
connectToMilonic();

//empty the mm_menus table
$query = "TRUNCATE mm_menus";
$result = mysql_query($query);

//empty the mm_items table
$query = "TRUNCATE mm_items";
$result = mysql_query($query);

//always insert this first into the mm_menus table (1,1,Main Menu,1,0,NULL)
//This is because you ALWAYS need a "Main Menu" entry for it to work
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='Main Menu', alwaysvisible='1',orientation='0', position='relative', menuwidth='100%'";
$result = mysql_query($query);

//insert  into mm_menus table(1,1,Home,NULL,NULL,NULL)
//This is for the top link
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='Home'";
$result = mysql_query($query);
$query = "INSERT INTO mm_items SET menuid='1', text='Home', url='index.php'";
$result = mysql_query($query);


//insert into mm_menus table (1,1,News,NULL,NULL,NULL)
//This is for the News link that is unique to SS
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='News'";
$result = mysql_query($query);
$query = "INSERT INTO mm_items SET menuid='1', text='News', url='index.php?news=yes'";
$result = mysql_query($query);

//close the milionic connection
closeMilonic();

//Connect to SS
connectToShopScript();

//get out of the shop script database that have a parent of 1, this will be the root menu
$query = "SELECT categoryID,name FROM SS_categories WHERE parent = '1'";
$result = mysql_query($query);

//close the shop script connection
closeShopScript();

//connect to the milonic database
connectToMilonic();

//insert what you got out of the shop script database into mm_menus table
while($array = mysql_fetch_array($result))
{
   $categoryID = $array['categoryID'];
   $name = $array['name'];
   $url = "index.php?categoryID=";
   $url .= $categoryID;
   //insert into mm_menus table (1,1,$name,NULL,NULL,NULL)
   $query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='$name'";   
   $myResult = mysql_query($query);
   
   $menuID = mysql_insert_id();
   
   closeMilonic();
   connectToShopScript();
   
        //Check to see if there are any submenus for the current category
   $query = "SELECT * FROM SS_categories WHERE parent = '$categoryID'";
   $ssResult = mysql_query($query);
   
   closeShopScript();
   connectToMilonic();
   
        //If no subcategories, then just insert a menu item
   if (mysql_num_rows($ssResult) == 0)
   {
      $query = "INSERT INTO mm_items SET menuid='1', text='$name',url='$url'";
      $itemsResult = mysql_query($query);
   }
   else  //Else, insert a menu and menu item and do the recursive call
   {
      $query = "INSERT INTO mm_items SET menuid='1', text='$name',showmenu='$name',url='$url'";
      $itemsResult = mysql_query($query);
      
      //Now, call a function to build the menu items for this category ID
      //Pass in $ssResult, $name, $menuid and $categoryID
      buildMenuTree($ssResult, $name, $menuID, $categoryID);
   }
}

/**********************************************************
  The last 3 inserts are 3 unique links added to the bottom of main menu
***********************************************************/

//insert into mm_menus (1,1,Site Credits,NULL,NULL,NULL)
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='Site Credits'";
$result = mysql_query($query);
$query = "INSERT INTO mm_items SET menuid='1', text='Site Credits', url='index.php?show_aux_page=14'";
$result = mysql_query($query);


//insert into mm_menus (1,1,M/A Com Parts,NULL,NULL,NULL)
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='M/A Com Parts'";
$result = mysql_query($query);
$query = "INSERT INTO mm_items SET menuid='1', text='M/A Com Parts', url='index.php?show_aux_page=10'";
$result = mysql_query($query);

//insert into mm_menus (1,1,NLT Repair Depot,NULL,NULL,NULL)
$query = "INSERT INTO mm_menus SET projectid='1', styleid='1', name='NLT Repair Depot'";
$result = mysql_query($query);
$query = "INSERT INTO mm_items SET menuid='1', text='NLT Repair Depot',url='index.php?show_aux_page=11'";
$result = mysql_query($query);

//close the milionic connection
closeMilonic();

//This confirmation is displayed because this script was setup as a "backend" function where the user clicks a button and a new window opens to run this PHP script
echo "Menus Updated Successfully! You may now <a href='javascript:window.close()'>close</a> this window.";

?>


If anyone has any questions about that, I'd be happy to answer them. I doubt anyone will get much use out of it since it's sorta unique to this e-commerce software (Shop Script), but maybe it will help anyway.


Poster: miner2049er
Dated: Wednesday February 28 2007 - 21:14:10 GMT

I'm having a problem implementing this PHP code sample, and wonder if street9009 or anyone else can assist.

If one of the moderators reads this, could they kindly pass on my email address/phone number to member street9009 who I am unable to contact or private-message.

Any solution I come up with I will post here for all to learn from.

So, here goes...

Everything seems to work OK, except that I can only get one level of drop-down menus to display...

Image

in this example above there should be another level named "BELOW BELOW US" but it wil not display.

For some reason I don't know, the code sample above does not insert that entry into the mm_items table (of the milonic menu database), even though the first level named "BELOW ABOUT US" does get inserted. Even adding another level named "BELOW BELOW BELOW ABOUT US" still only gets one sublevel to show like in the image I included.

I've placed the above code sample in the file convert.php and this is where it is called:

include("mm_config.php"); // This file contains all of the user editable parameters

include("mm_phpmenu.php"); // This is the file containing all of the PHP functions

include "convert.php";

buildMySQLMenu(1); // This line builds the menu from MySQL data tables.

Here are the rows in the SS_categories table (where my menu source data is located) :

categoryID - parent - name

1 - 0 - Top
2 - 1 - ABOUT US
18 - 1 - JOIN US
19 - 1 - CLASSES
30 - 1 - EVENTS
31 - 2 - BELOW ABOUT US
32 - 18 - BELOW JOIN US
17 - 1 - LOCATIONS
15 - 1 - DONATE
33 - 31 - BELOW BELOW ABOUT US
34 - 33 - BELOW BELOW BELOW ABOUT US

If clarification of anything is required, please let me know.

Any assistance would be most appreciated!


Poster: Andy
Dated: Thursday March 1 2007 - 9:50:38 GMT

Hi,

Send us your data and we'll take a look


Poster: miner2049er
Dated: Tuesday March 20 2007 - 16:08:25 GMT

Thanks for the reply. Data to come soon.


Poster: miner2049er
Dated: Monday March 26 2007 - 16:47:09 BST

So after running the above source data through street9009's code, this is what resulting Milonic Menu SQL table data comes out (see below.)

As you can see, there are no menu levels named

BELOW BELOW ABOUT US

BELOW BELOW BELOW ABOUT US

Only one sub-menu gets created.

Does anyone have some advice? If any more details are needed, please let me know.



-- phpMyAdmin SQL Dump
-- version 2.6.0-rc1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 26, 2007 at 12:07 AM
-- Server version: 4.0.20
-- PHP Version: 4.3.8
--
-- Database: `milonic`
--

-- --------------------------------------------------------

--
-- Table structure for table `mm_items`
--

CREATE TABLE `mm_items` (
`itemid` int(11) NOT NULL auto_increment,
`menuid` int(11) NOT NULL default '0',
`text` text,
`url` varchar(255) default NULL,
`showmenu` varchar(40) default NULL,
PRIMARY KEY (`itemid`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;

--
-- Dumping data for table `mm_items`
--

INSERT INTO `mm_items` VALUES (1, 1, 'HOME', 'index.php', NULL);
INSERT INTO `mm_items` VALUES (2, 1, 'ABOUT US', 'index.php?categoryID=2', 'ABOUT US');
INSERT INTO `mm_items` VALUES (3, 3, 'BELOW ABOUT US', 'index.php?categoryID=31', 'BELOW ABOUT US');
INSERT INTO `mm_items` VALUES (4, 1, 'JOIN US', 'index.php?categoryID=18', 'JOIN US');
INSERT INTO `mm_items` VALUES (5, 5, 'BELOW JOIN US', 'index.php?categoryID=32', NULL);
INSERT INTO `mm_items` VALUES (6, 1, 'CLASSES', 'index.php?categoryID=19', NULL);
INSERT INTO `mm_items` VALUES (7, 1, 'EVENTS', 'index.php?categoryID=30', NULL);
INSERT INTO `mm_items` VALUES (8, 1, 'LOCATIONS', 'index.php?categoryID=17', NULL);
INSERT INTO `mm_items` VALUES (9, 1, 'DONATE', 'index.php?categoryID=15', NULL);

-- --------------------------------------------------------

--
-- Table structure for table `mm_menus`
--

CREATE TABLE `mm_menus` (
`menuid` int(11) NOT NULL auto_increment,
`projectid` int(11) NOT NULL default '0',
`styleid` int(11) NOT NULL default '0',
`name` varchar(40) NOT NULL default '',
`alwaysvisible` tinyint(1) default NULL,
`orientation` tinyint(1) default NULL,
`overflow` varchar(20) default NULL,
PRIMARY KEY (`menuid`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;

--
-- Dumping data for table `mm_menus`
--

INSERT INTO `mm_menus` VALUES (1, 1, 1, 'Main Menu', 1, 1, NULL);
INSERT INTO `mm_menus` VALUES (2, 1, 1, 'HOME', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (3, 1, 1, 'ABOUT US', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (4, 1, 1, 'BELOW ABOUT US', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (5, 1, 1, 'JOIN US', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (6, 1, 1, 'CLASSES', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (7, 1, 1, 'EVENTS', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (8, 1, 1, 'LOCATIONS', NULL, NULL, NULL);
INSERT INTO `mm_menus` VALUES (9, 1, 1, 'DONATE', NULL, NULL, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `mm_projects`
--

CREATE TABLE `mm_projects` (
`projectid` int(11) NOT NULL auto_increment,
`menuCloseDelay` int(11) NOT NULL default '500',
`menuOpenDelay` int(11) NOT NULL default '150',
`subOffsetTop` tinyint(1) NOT NULL default '0',
`subOffsetLeft` tinyint(1) NOT NULL default '0',
`name` varchar(100) default NULL,
PRIMARY KEY (`projectid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

--
-- Dumping data for table `mm_projects`
--

INSERT INTO `mm_projects` VALUES (1, 500, 150, 2, -3, 'Minimalist Menu');

-- --------------------------------------------------------

--
-- Table structure for table `mm_styles`
--

CREATE TABLE `mm_styles` (
`styleid` int(11) NOT NULL auto_increment,
`name` varchar(40) NOT NULL default '',
`oncolor` varchar(6) default NULL,
`onbgcolor` varchar(6) default NULL,
`offcolor` varchar(6) default NULL,
`offbgcolor` varchar(6) default NULL,
`padding` tinyint(4) default NULL,
`separatorsize` tinyint(4) default NULL,
`borderwidth` tinyint(4) default NULL,
`fontfamily` varchar(25) default NULL,
`fontsize` varchar(6) default NULL,
PRIMARY KEY (`styleid`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

--
-- Dumping data for table `mm_styles`
--

INSERT INTO `mm_styles` VALUES (1, 'miniStyle', 'FFFFFF', 'F67979', '000000', 'EEEEEE', 6, 1, 1, 'verdana', '12px');


Poster: miner2049er
Dated: Tuesday March 27 2007 - 18:53:55 BST

I also noticed further down in this other thread...

http://www.milonic.com/forum/viewtopic.php?t=7220

that people were having a similar problem with people getting deeper menu levels to display. Specifically member "jonjon" on page 2 of the thread.

Could this be related to the problem I am having?


Poster: Ruth
Dated: Wednesday March 28 2007 - 4:42:43 BST

Hi,

I've posted to Milonic since I have no knowledge of the mysql/php menus. You did note that street said his 'code' was specific to that particular e-commerce software - Shop Script?

Ruth


Poster: miner2049er
Dated: Wednesday March 28 2007 - 17:31:06 BST

In a post on March 7, the administrator Andy wrote "Hi, Send us your data and we'll take a look", which I have done now in this thread, and am hoping for any insights.

The code is earlier in this thread, plus the source and destination data.

As mentioned previously, the source data I use (and as used by the shop script earlier) is quite basic, and is...

categoryID - parent - name

1 - 0 - Top
2 - 1 - ABOUT US
18 - 1 - JOIN US
19 - 1 - CLASSES
30 - 1 - EVENTS
31 - 2 - BELOW ABOUT US
32 - 18 - BELOW JOIN US
17 - 1 - LOCATIONS
15 - 1 - DONATE
33 - 31 - BELOW BELOW ABOUT US
34 - 33 - BELOW BELOW BELOW ABOUT US

but somehow it doesn't get transformed into a correct Milonic menu.

Please assist.