Jump to content

Nested PHP


chris8726

Recommended Posts

I am trying to place a section of PHP inside another section of PHP to create a persistent menu system.  What it is, is a main menu that when an option is selected uses PHP to bring up another menu, and when an option is selected in that menu it uses PHP to either bring up another menu or a description of an item.  You can look at the system here.  What I want to do with it is have the menu stay on the selected item as you go through.  I can get the top level to stay, but the lower levels of the menu are their own php scripts and I don't know how to make another php script work inside another script.  If you have any ideas please let me know.

Link to comment
https://forums.phpfreaks.com/topic/49503-nested-php/
Share on other sites

Hi

 

I think you should be doing this with one script? (nesting??)

 

<?php

$menu1value = $_POST["menu1"];
$menu2value = $_POST["menu2"];
$menu3value = $_POST["menu3"];

// build the select
$menu1 = "<select name='menu1' onchange='Submit();'><option value='a'>a</option></option2.3.4.4.>";
// this line selects the posted value (there might be a better way to do it)
$menu1 = str_replace("option value='$menu1value'>", "option value='$menu1value'> selected", $menu1); 

if ($menu1value == "a") {
$menu2 = "<select name='menu2' onchange='Submit();'><option value='z'>z</option></option2.3.4.4.>";
} 
else if ($menu1value == "b") {
// whatever
}
$menu2 = str_replace("option value='$menu2value'>", "option value='$menu2value' selected>", $menu1); 

// repeat above for menu3

// html code etc...
echo "<form method='post'>";
echo $menu1;
echo $menu2;
echo $menu3;
echo "</form>
// blah blah more html
?>

 

or something along those lines :)

 

Does that help?

 

Cheers,

tdw

Link to comment
https://forums.phpfreaks.com/topic/49503-nested-php/#findComment-244331
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.