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:25

PHP Variables


Poster: alanpollenz
Dated: Saturday December 1 2007 - 5:01:32 GMT

I have been through the forums this evening trying all the solutions to this problem. For the life of me, I cannot get a php variable into the menu.

Here is the code from my main page:

Code:
<!-- START NAVIGATION -->
<? print $this_first_name.'<br>'; ?>
                  <script src="<? echo $baseurl; ?>/js/milonic_src.js" type=text/javascript></script>
                  <script type="text/javascript">
                     <!--
                     if(ns4)_d.write("<scr"+"ipt src=<? echo $baseurl; ?>/js/mmenuns4.js type=text/javascript><\/scr"+"ipt>");      
                     else _d.write("<scr"+"ipt src=<? echo $baseurl; ?>/js/mmenudom.js type=text/javascript><\/scr"+"ipt>");
                      -->
                  </script>
                  <script src="<? echo $baseurl; ?>/include/menu.data.php" type=text/javascript></script>   

<!-- END NAVIGATION -->


As you can see, I renamed menu_data.js to menu.data.php (I also tried menu_data.php. The print statement is there to show that the variable I want to pass does exist. I have the following in my menu.data.php file:

Code:
aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<?php echo $this_first_name; ?>;");


When I mouseover the 'Home" menu item, the following is the link displayed in the status bar and the link you are taken to when the menu item is clicked:

http://www.newwaveswimteam.org/index.php?name=

The php variable is not appended to the URL.

If you want to see this in action, I have created a test user with the first name Test and last name User. You can log in at http://www.swimteammanager-dev.com with username testuser and password testuser. You will see the menu with the name Test just above the menu. This is from the print statement in the first codesnippet.Mouseover and then click on Home. You'll see that the frst name is not appended to the url even though it does exist.

Any help would be greatly appreciated.

Alan Pollenz

Re: PHP Variables


Poster: Ruth
Dated: Saturday December 1 2007 - 6:02:37 GMT

Hi,

OK, this is not something I know much about, but I downloaded your page, renamed the menu.data.php to menu_data.php [only because that's how I've always seen it, I don't know if it makes a difference] Then I change the Home aI string to

Code:
aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name='<?php echo $this_first_name; ?>';");


I saved that page I downloaded as .htm and I don't know if or why that would make a difference, but figured I'd tell you. Anyway, when I opened the page I saved with the new data file and clicked the home item I went to a page showing the menu at the left and then in the center top area had this.

Your location: Home
On the Crest of the Wave
Bring in a Toy

I don't know what the address bar is supposed to show, but in FF it showed

Code:
http://www.newwaveswimteam.org/index.php?name='%3C?php%20echo%20$this_first_name;%20?%3E'


As I said I don't know about this stuff, so I don't know what it's supposed to be, but I did get to a page :)

Ruth

Re: PHP Variables


Poster: alanpollenz
Dated: Sunday December 2 2007 - 19:55:53 GMT

Hi Ruth,

That did not work, but thanks for the suggestion. The reason the address bar showed "http://www.newwaveswimteam.org/index.php?name='%3C?php%20echo%20$this_first_name;%20?%3E'" is because with the single quotes around <?php echo $this_first_name; ?> php reads $this_first_name as a literal string not a variable. Also, it looks like the browser replaced the $ and spaces.

If it were working properly and you were logged in as testuser and clicked the "Home" menu item, it should take you to http://www.newwaveswimteam.org/index.php?name=Test

Thanks again.

Alan

Re: PHP Variables


Poster: Ruth
Dated: Sunday December 2 2007 - 22:30:12 GMT

Hi,

You have this as the url in your menu_data.php file when I go to the dev section to try and test it

Code:
http://www.newwaveswimteam.org/index.php?name=


Doesn't it need the variable?
Code:
<? echo $this_first_name; ?>;


I am going to pass this on to Milonic since I don't know why it isn't working. I did find one post about variables back in January, but don't know if this will help. viewtopic.php?p=40983#p40983

Ruth

Re: PHP Variables


Poster: alanpollenz
Dated: Monday December 3 2007 - 1:46:17 GMT

Hi Ruth,

The actual line from the menu_data.php file is

Code:
aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<?php echo $this_first_name; ?>;");


I have tried it both that way and as follows:

Code:
aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<? echo $this_first_name; ?>;");


The reason it appears to end after name= is because the PHP variable is not being parsed for some reason. I have looked at the thread you included but nothing jumps out. It appears as though I am following the correct procedures, just without success.

Alan

Re: PHP Variables


Poster: alanpollenz
Dated: Monday December 3 2007 - 2:03:20 GMT

Interestingly, if I changed the way the script is called from:

Code:
<script src="/include/menu_data.php" type=text/javascript></script>


to:
Code:
<? include ($basedir.'include/menu_data.php'); ?>


And place <script type="text/javascript"> at the start of menu_data.php and </script> at the end of menu_data.js, it works fine. The only problem, and this is what I'm really trying to avoid, is that when it is called as a php include all the menu_data.php code is displayed in the page source and I want to avoid this. When called as a js file the page menu_data.php code is not displayed in the page source.

Alan