Simple Case Switching for Dynamic Content

72dpi 72dpi is offline Offline May 25th, 2005, 10:37 pm |
0
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.
Quick reply to this message  
PHP Syntax
  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:


Similar Threads
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC