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: Archived Topics for the old Version 3.0 JavaScript Menu
Forum Topic: Click to view post
Last Updated: Wednesday July 18 2012 - 06:07:31

PHP echo within menu item


Poster: phptek
Dated: Friday July 19 2002 - 5:16:51 BST

I'd like to be able to echo a php variable extracted from a DB into my milonic DHTML menu items.
I'm using in-page javascript with double quotes escaped etc.
I am calling the menus thus:

<a onMouseOver=\"popup('events')\" onMouseOut=\"popdn()\" href='events.php'><img src='path/to/img.gif'></a>

The menu "works" when the javascript is in an external 'global.js' file (PHP vars don't but menu per-se does) but now I get the error: 'menuevents' is not defined'

Unfortunately it's all on our development server so I can't point you out to an example.
Either way - if anyone has been able to echo PHP vars extracted from a DB - and they are able to help me,
that would be great!

The menu definiton for 'events' is shown below.
Cheers.
Russ

addmenu(menu=[
\"events\", // Menu Name - This is needed in order for this menu to be called
110, // Menu Top - The Top position of this menu in pixels
134, // Menu Left - The Left position of this menu in pixels
170, // Menu Width - Menus width in pixels
1, // Menu Border Width
, // Screen Position - here you can use \"center;left;right;middle;top;bottom\" or a combination of \"center:middle\"
style01, // Properties Array - this array is declared higher up as you can see above
0, // Always Visible - allows this menu item to be visible at all time (1=on or 0=off)
, // Alignment - sets this menu elements text alignment, values valid here are: left, right or center
effect, // Filter - Text variable for setting transitional effects on menu activation - see above for more info
0, // Follow Scrolling Top Position - Tells this menu to follow the user down the screen on scroll placing the menu at the value specified.
0, // Horizontal Menu - Tells this menu to display horizontaly instead of top to bottom style (1=on or 0=off)
0, // Keep Alive - Keeps the menu visible until the user moves over another menu or clicks elsewhere on the page (1=on or 0=off)
, // Position of TOP sub image left:center:right
, // Set the Overall Width of Horizontal Menu to specified width or 100% and height to a specified amount
0, // Right To Left - Used in Hebrew for example. (1=on or 0=off)
0, // Open the Menus OnClick - leave blank for OnMouseover (1=on or 0=off)
, // ID of the div you want to hide on MouseOver (useful for hiding form elements)
, // Background image for menu Color must be set to transparent for this to work
0, // Scrollable Menu
, // Reserved for future use
,\"&nbsp;$EventName\",\"?evntID=$EventID\",,,1
])


Poster: Andy
Dated: Friday July 19 2002 - 8:16:59 BST

You can rename the .js file .php and then this file will get parsed through the PHP interpreter.

This will allow you to add your variables like a normal PHP page.

Cheers
Andy

SweetAz!


Poster: phptek
Dated: Saturday July 20 2002 - 4:23:12 BST

Hey thanks a million Andy!

You know it's a rare occasion when something not only works, but first time? - Well I'll be darned if it didn't work first time for me!

Cheers.
Russ


Poster: dagon
Dated: Sunday July 21 2002 - 22:05:18 BST

Andy, do you have a working example of method you suggest? For me it don't works (see my old posts).

Some sample Code


Poster: phptek
Dated: Monday July 22 2002 - 2:15:31 BST

Nero:

I tried to mail you but it failed! :-(
So I'll incoporate my code (file: menu_array.inc)

1). Convert menu_array.js to menu_array.inc and include it *before* the call to the mmenu.js file:

//Include PHP'ised javascript file: "menu_array.inc" Delivers DHTML Menus on the fly:
include "menu_array.inc";
echo "
<script type='text/javascript' language='javascript' src='js/mmenu.js'></script>

2).menu_array.inc:
<?php
#File info: \"menu_array.inc\" A formerly .js file - php style. Allows us to generate a
#Milonic DHTML menu item on the fly from MySQL
#Russ Michell July 2002 :: russ __at__ theruss.com - http://www.theruss.com

echo "
<script language='javascript' type='text/javascript'>

/*--------------------------------------------------------------------------------------------
Milonic DHTML Menu
Written by Andy Woolley
Copyright 2002 (c) Milonic Solutions. All Rights Reserved.
Plase visit http://www.milonic.co.uk/menu or e-mail menu3 __at__ milonic.com
You may use this menu on your web site free of charge as long as you place prominent
links to http://www.milonic.co.uk/menu and you inform us
of your intentions with your URL AND ALL copyright notices remain in place in all files
including your home page.
Comercial support contracts are available on request if you cannot comply with the above rules.

If you are having difficulty with the menu please read the FAQ at http://www.milonic.co.uk/menu/faq.php before contacting us.
-----------------------------------------------------------------------------------------------*/

//The following line is critical for menu operation, and MUST APPEAR ONLY ONCE.
menunum=0;menus=new Array();_d=document;function addmenu(){menunum++;menus[menunum]=menu;}function dumpmenus(){mt=\"<script language=javascript>\";for(a=1;a<menus.length;a++){mt+=\" menu\"+a+\"=menus[\"+a+\"];\"}mt+=\"<\/script>\";_d.write(mt)}
//Please leave the above line intact. The above also needs to be enabled if it not already enabled unless you have more than one _array.js file

effect = \"Fade(duration=0.4);Alpha(style=0,opacity=82);Shadow(color='#333333', Direction=135, Strength=5)\" // Special effect string for IE5.5 or above please visit http://www.milonic.co.uk/menu/filters_sample.php for more filters

////////////////////////////////////
// Editable properties START here //
////////////////////////////////////

timegap=500 // The time delay for menus to remain visible
followspeed=5 // Follow Scrolling speed
followrate=40 // Follow Scrolling Rate
suboffset_top=10 // Sub menu offset Top position
suboffset_left=10 // Sub menu offset Left position

style01=[ // EasySampleStyle is an array of properties. You can have as many property arrays as you need
\"FFFFFF\", // Mouse Off Font Color
\"666666\", // Mouse Off Background Color (use zero for transparent in Netscape 6)
\"666666\", // Mouse On Font Color
\"CCCCCC\", // Mouse On Background Color
\"FFCC00\", // Menu Border Color
\"11\", // Font Size (default is px but you can specify mm, pt or a percentage)
\"normal\", // Font Style (italic or normal)
\"bold\", // Font Weight (bold or normal)
\"arial\", // Font Name
0, // Menu Item Padding or spacing
\"images/icons/arrow.gif\", // Sub Menu Image (Leave this blank if not needed)
0, // 3D Border & Separator bar
, // 3D High Color
, // 3D Low Color
, // Current Page Item Font Color (leave this blank to disable)
, // Current Page Item Background Color (leave this blank to disable)
\"images/icons/arrow.gif\", // Top Bar image (Leave this blank to disable)
, // Menu Header Font Color (Leave blank if headers are not needed)
, // Menu Header Background Color (Leave blank if headers are not needed)
, // Menu Item Separator Color
]

//Menu Array 01 :: dynamic array definition for the mugshots' section gallery menu:
//===============================================================================

addmenu(menu=[
\"gallery\", // Menu Name - This is needed in order for this menu to be called
131, // Menu Top - The Top position of this menu in pixels
115, // Menu Left - The Left position of this menu in pixels
100, // Menu Width - Menus width in pixels
1, // Menu Border Width
, // Screen Position - here you can use \"center;left;right;middle;top;bottom\" or a combination of \"center:middle\"
style01, // Properties Array - this array is declared higher up as you can see above
0, // Always Visible - allows this menu item to be visible at all time (1=on or 0=off)
, // Alignment - sets this menu elements text alignment, values valid here are: left, right or center
effect, // Filter - Text variable for setting transitional effects on menu activation - see above for more info
0, // Follow Scrolling Top Position - Tells this menu to follow the user down the screen on scroll placing the menu at the value specified.
0, // Horizontal Menu - Tells this menu to display horizontaly instead of top to bottom style (1=on or 0=off)
0, // Keep Alive - Keeps the menu visible until the user moves over another menu or clicks elsewhere on the page (1=on or 0=off)
, // Position of TOP sub image left:center:right
, // Set the Overall Width of Horizontal Menu to specified width or 100% and height to a specified amount
0, // Right To Left - Used in Hebrew for example. (1=on or 0=off)
0, // Open the Menus OnClick - leave blank for OnMouseover (1=on or 0=off)
, // ID of the div you want to hide on MouseOver (useful for hiding form elements)
, // Background image for menu Color must be set to transparent for this to work
0, // Scrollable Menu
, // Reserved for future use
";
//end PHP echo - Begin dynamic generation of DHTML menu items:

$sql_gallerys = "SELECT GalleryName,GalleryID FROM gallerys ORDER BY GalleryDateFrom";
$res_gallerys = mysql_query($sql_gallerys) or die("DHTML/SQL Homepage Error.\n" . "$sql_gallerys");
//No Gallerys have been found - display nothing:
if(mysql_num_rows($res_gallerys) < 1)
{
echo "";
}
//Gallerys have been found - display no. DB rows found as menu items:
else
{
while($row=mysql_fetch_assoc($res_gallerys))
{
extract($row);
echo "
,\"&nbsp;$GalleryName\",\"mugshots.php?galleryID=$GalleryID\",,,1
";
}//end looping
//Complete JS array definition:
echo "])";
}

echo "
dumpmenus();
</script>\n\n";
//end PHP echo


?>

Good luck!
Russ :-)


Poster: dagon
Dated: Monday July 22 2002 - 21:56:16 BST

:D IT WORKS PERFECTLY GUYS!!!!!! Thank you very very much Russ!! I was trying to do that by a long time... I'm thinking I'm blind... 8)

It`s work but.... BUG


Poster: WarLock
Dated: Tuesday July 30 2002 - 7:15:42 BST

Yep it work perfectly but i go a strange bug or someting like that
i made 2 variable in my body array.php3 [your conversion of .js files to php]

$Link1 = "c:/program files/easyphp/www/codexbeta/news/"
$Link2 = "http://www/codexbeta/news/"

in my body_array.php3 i make this

(------------------------------------------------------------)
addmenu(menu=[\"news\",
,,140,1,\"\",plain_style,,,effect,,,,,,,,,,,,
,\"Nouvelle du Jours\", \"$Link1 . news.php3\",,,1
,\"Index des Nouvelles\", \"archives.php3\",,,1
,\"Ajouter une Nouvelle\", \"admin/index.php3\",,,1
])
(------------------------------------------------------------)

The link dont working because the link start with this "c:/"
and if i change for this

(------------------------------------------------------------)
addmenu(menu=[\"news\",
,,140,1,\"\",plain_style,,,effect,,,,,,,,,,,,
,\"Nouvelle du Jours\", \"$Link2 . news.php3\",,,1
,\"Index des Nouvelles\", \"archives.php3\",,,1
,\"Ajouter une Nouvelle\", \"admin/index.php3\",,,1
])
(------------------------------------------------------------)

This one work well because the link start with "http://"

It is a Bug or i made something bad ?????????

Plz someone HELP ME MADE WORKING $Link1 !!!!!!!!!!!!!!!!


Poster: phptek
Dated: Tuesday July 30 2002 - 7:44:11 BST

Just make your link from this:
$Link1 = "c:/program files/easyphp/www/codexbeta/news/"

to this:
$Link1 = "/www/codexbeta/news/" (or similar 'local' URL)

I'm guessing that this is a relative link (within your computer's filesystem) although I have no idea what 'easyphp' is and what it's doing in your 'program files' directory!

phptek

Ok i see


Poster: WarLock
Dated: Wednesday July 31 2002 - 7:14:35 BST

Thx phptek

Ok i see

$Link1 = "c:/program files/easyphp/www/codexbeta/news/"
$Link2 = "http://www/codexbeta/news/"

and for me in locale net

$HTTP_REFERER = "http://warlock/Was"

And if i call this Setp 1 its OK but i need to view news.php3
in my main Frame
(----------------STEP 1----------------------------)
addmenu(menu=[\"news\",
,,140,1,\"\",plain_style,,\"left\",effect,,,,,,,,,,,,
,\"News of the day\", \"$HTTP_REFERER . /news/news.php3\",,,1
,\"Index of News\", \"$HTTP_REFERER . /news/archives.php3\",,,1
,\"Admin News\", \"$HTTP_REFERER . /news/admin/index.php3\",,,1
])
(-----------------------------------------------------)

I Try to make Step 2 and it cause a
stackover flow at line 41 ???

(-----------------STEP 2-----------------------------)
addmenu(menu=[\"news\",
,,140,1,\"\",plain_style,,\"left\",effect,,,,,,,,,,,,
,\"News of the day\", \"$HTTP_REFERER . /news/news.php3 target=main;sourceframe=main\",,,1
,\"Index of News\", \"$HTTP_REFERER . /news/archives.php3\",,,1
,\"Admin News\", \"$HTTP_REFERER . /news/admin/index.php3\",,,1
])
(-----------------------------------------------------)


Now what i made wrong ??? someone can help me
P.S And can i refresh my web page (all frame) with Milonic DHTML Menu
WarLock