Jump to content

Php menu help


Aplep

Recommended Posts

Hello!

I'm a noob in terms of php and I want to ask you something.

How could I create a menu like this:

Top T | Top CT

-> when I press Top T, another 2 menu options (href) will appear bellow (and the Top T and Top CT will remain) and when I press TOP ct the same.

But I want all in one .php file, so how can I do it ?  :shy:

Thank you very much!

Link to comment
https://forums.phpfreaks.com/topic/265417-php-menu-help/
Share on other sites

Hmm . . . what you are describing *can* be done in PHP, but is normally done in JavaScript so there is no page refresh.

 

But, here is a rudimentary PHP example

<?php

$subLinks = '';
switch($_GET['t'])
{
    case 'T':
        $subLinks .= "<a href='pageTA.php'>T-A</a>\n"
        $subLinks .= "<a href='pageTB.php'>T-B</a>\n"
        break;
    case 'TC':
        $subLinks .= "<a href='pageTCA.php'>TC-A</a>\n"
        $subLinks .= "<a href='pageTCB.php'>TC-B</a>\n"
        break;
}
?>

<a href="index.php?t=T">Top T</a> <a href="index.php?t=TC">Top TC</a><br>
<?php echo $subLinks; ?>

Link to comment
https://forums.phpfreaks.com/topic/265417-php-menu-help/#findComment-1360259
Share on other sites

you put it altogether now.

 

might be errors not tested the example ok.

 

<?php

echo"<a href=" ".$_SERVER["PHP_SELF"]."?a="a" ">link 1</a><br/><br/>";

echo"<a href=" ".SERVER["PHP_SELF"]."?b="b" ">link 2</a>";

if $_GET["a"]=="a"){

echo " this is page a";

break;
}


if $_GET["b"]=="b"){

echo " this is page b";

break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/265417-php-menu-help/#findComment-1360270
Share on other sites

Thank you.

 

One more noob question:

 

Where how could I put the content of 'pageTA.php' ; pageTB.php ; pageTCA.php ; pageTCB.php without making separate pages ?

 

Why would you want to? It is much better to have smaller, well-defined scripts rather than trying to create one huge script. But, you could create one script that controls which content is displayed. Again, here is a ROUGH example. There are hundreds of ways you could accomplish this and the best solutions would be dictated by the specific configuration/complexity of what you are trying to do. In this example youwould have a single index.php page that the user loads each time. But, you would have separate files for the content to load based upon the selection made.

 

<?php

$base_page = 'test.php';

//Detemine the menu to display
$menu = "<a href='{$base_page}?tab=T'>Top T</a> \n";
$menu .= "<a href='{$base_page}?tab=TC'>Top TC</a>\n";;
$menu .= "<br>\n";

switch($_GET['tab'])
{
    case 'T':
        $menu .= "<a href='{$base_page}?tab=T&page=T-A'>T-A</a>\n";
        $menu .= "<a href='{$base_page}?tab=T&page=T-B'>T-B</a>\n";
        break;
    case 'TC':
        $menu .= "<a href='{$base_page}?tab=TC&page=TC-A'>TC-A</a>\n";
        $menu .= "<a href='{$base_page}?tab=TC&page=TC-B'>TC-B</a>\n";
        break;
}

//Detemine the content to display
switch($_GET['page'])
{
    case 'T-A':   // Create files for each page:
    case 'T-B':   // T-A.php, T-B.php, etc. with
    case 'TC-A':  // just the content to displaye
    case 'TC-B':
        $content_include = $_GET['page'] . 'php';
        break;
    default:
        $content_include = 'nopage.php'; //Page to display when nothing is selected
}

?>
<html>
<head>

</head>
<body>

<!-- Begin Menu -->
<?php echo $menu; ?>
<!-- End Menu -->

<br><br>

<!-- Begin Content -->
<?php include($content_include); ?>
<!-- End Content -->

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/265417-php-menu-help/#findComment-1360275
Share on other sites

this is a nice way aswell



<html>

<head>

<head>

<title>

</title>

</head>

<body>


<?php session_start();


$self=$_SERVER['PHP_SELF'];


echo"<a href='$self?a=a '>link 1</a>";


echo"<br/><br/>";


echo"<a href='$self?a=b '>link 2</a>";


if($_GET['a']=="a"){

echo " <center> <br /><p> <b> This is page a </b> </p> </center>  

</body>

</html>";

exit;

}


if($_GET['a']=="b"){

echo " <center> <br /><p> <b> This is page b </b> </p> </center> 
</body> 
</html>";

exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/265417-php-menu-help/#findComment-1360282
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.