Archive for April, 2009

Select a menu

This post is specifically to answer a twitter question:

PHP was more designed to control your HTML rather than the other way around. What you are trying to do could be handled with Javascript, but PHP is a better solution. See if this makes a little more sense…
<?php if ($_SERVER['PHP_SELF'] == "bluepage.php") {
               include('bluemenu.php');
         }
          if ( $_SERVER['PHP_SELF'] == "redpage.php") {
               include('redmenu.php');
         }
?>

But the better way is to use the “switch” like this:
<?php
          $page = $_SERVER['PHP_SELF'];
               switch ( $page ){
                      case "bluepage.php":
                           include ('bluemenu.php');
                      break;
                     case "redpage.php":
                            include ('redmenu.php');
                      break;
                      default: //will execute if we didnt match any above
                        include ('standardmenu.php');
                      break;
                 }
?>

I hope that helps some

,

No Comments