944,149 Members | Top Members by Rank

Ad:
  • PHP Code Snippet
  • Views: 4160
  • PHP RSS
0

Simple Case Switching for Dynamic Content

by on May 25th, 2005
Case switching is a neat way to make your site a bit more dynamic. it gives you the ability to show blocks of information "on the fly".

By attaching the variable name "Content" to our link, we pass that condition in the query string. Note that on the last link, our Default content will show, since we have not passed the variable.
PHP Code Snippet (Toggle Plain Text)
  1. < href="<?php echo $_SERVER['PHP_SELF']; ?>?Content=one">Case One</a><br />
  2. < href="<?php echo $_SERVER['PHP_SELF']; ?>?Content=two">Case Two</a><br />
  3. < href="<?php echo $_SERVER['PHP_SELF']; ?>?Content=two">Case Tthree</a><br />
  4. < href="<?php echo $_SERVER['PHP_SELF']; ?>Main</a>
  5. <br />
  6. <br />
  7.  
  8. <?php
  9. switch ($Content)
  10. {
  11. case one:
  12. echo "This is our First Case";
  13. break;
  14.  
  15. case two:
  16. echo "This is our Second Case";
  17. break;
  18.  
  19. case three:
  20. echo "This is our Third Case";
  21. break;
  22.  
  23. default:
  24. echo"This is our default Content in case nothing was selected!";
  25. }
  26. ?>
  27.  
  28.  
  29. hope this helps a newbie!
  30. I
  31.  
Message:
Previous Thread in PHP Forum Timeline: Automating a script
Next Thread in PHP Forum Timeline: Sending E-mail Within PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC