Dynamic Menu using parameter passed via get and a require

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bob_brid
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2010 1:08 pm

Dynamic Menu using parameter passed via get and a require

Post by bob_brid »

Please can someone help me with the following problem? I believe the code I have is rendering correctly but not being executed in time.

I've passed a parameter from one page to another anit recieves it OK (will echo out and display within the page fine).
I have also used requires for certain repeated elements of common pages.
I'm now trying to use the paramater to call one of a set of specific menu lists that are tailored to the parameter being passed between pages.

Code: Select all

echo "require('nav_".$PPP.".php')";


But it fails to call in the menu item correctly.

I can get it to create the following if $PPP passes 1

Code: Select all

<?php
require('nav_1.php');
?>
but it just writes it to the page rather than use it how I intended.

I can copy its output into a page and open that page and menu list 1 will appear.

Obviously this is not much use for a dynamic menu system.

Suggestion as to how I may get it to execute rather than display much appreciated.

Cheers,

Bob
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Dynamic Menu using parameter passed via get and a require

Post by requinix »

"nav_1.php" is just a string. You can do whatever you want to it. Want 1 to be a variable instead? Go ahead.

Code: Select all

'nav_' . $PPP . '.php'
You can hand that off to require() perfectly fine.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Dynamic Menu using parameter passed via get and a require

Post by AbraCadaver »

Code: Select all

echo "require('nav_".$PPP.".php')";
Why are you echoing your require()? Why do you have quotes around your require()?

Code: Select all

require('nav_'.$PPP.'.php');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
bob_brid
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2010 1:08 pm

Re: Dynamic Menu using parameter passed via get and a require

Post by bob_brid »

Many thanks to both of you (tasairis & AbraCadaver),

I had been trying to use echo/print to dynamically write an include within an include to do what turned out easier than I was trying to make it.

Works a treat now.

Thanks again,

Bob
Post Reply