Page 1 of 1

Switch Command

Posted: Wed Nov 12, 2008 10:46 am
by swjohnson
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I am a dbase programmer - at least I was 15 years ago when I got burned out. This is my first serious look at reestablishing my programming skills, although I have done some HTML progrmming over the years, it left quite a bit to be desired. I am a firm believer in subroutines, something HTML couldn't fully accomplish. I have about 30 pages on the website I am developing and don't want to have to maintain 30 fully coded pages.

Are there any major problems with the concept of the following code? (I substituted [] for <>)

Code: Select all

<? php
 
include(header.php)
 
$bodytext = 0; //This actually gets its value from the header in the mapped areas so I will delete this from the real code
 
switch ($bodytext) {
 
   case "1" :
   include(aboutus.php);
   break;
 
   case "2" :
   include(contactus.php);
   break;
 
   default :
   include(index.php);
   break;
 
   }
 
include(footer.php)
 
?>
Thanks in advance,

Steve


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Switch Command

Posted: Wed Nov 12, 2008 10:51 am
by infolock
No, except if you take off the "" around the case statements it will be evaluated as an integer instead of a string, meaning on a low level point of view it will be executed quicker ;)

but that's just me being very picky..

Re: Switch Command

Posted: Wed Nov 12, 2008 11:11 am
by swjohnson
DUH! Thanks for the suggestion, Jonathon. And thanks for the rapid response.
Steve

I notice there is no smilie for slapping my forehead!

Re: Switch Command

Posted: Wed Nov 12, 2008 11:13 am
by infolock
haha, but there is one for banging it against a brick wall :banghead: :D