ItsWesYo Posted June 29, 2007 Share Posted June 29, 2007 I know this can cause a big file size and such, but I want to test something. index.php <?php $page = ((isset($_REQUEST['page']))?($_REQUEST['page'])'')); switch($page) { case "about": { echo("about us page"); break;} case "contact": { echo("contact page"); break;} case "link2us": { echo("link to us page"); break;} case "affiliates": { echo("affiliates page"); break;} default: { echo(" main page "); break;} } ?> I am just wondering: How would I add in mysql stuff? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 29, 2007 Share Posted June 29, 2007 I've done this using include() in the cases instead of the whole page. You don't need braces around the case, btw. You can add MySQL functions just like you would normally. You can add the connection code (connect, select_db) before the switch and page-specific queries in the cases. Quote Link to comment Share on other sites More sharing options...
ItsWesYo Posted June 29, 2007 Author Share Posted June 29, 2007 Thank you for your quick reply =) Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 29, 2007 Share Posted June 29, 2007 To answer your request as to how I used switch on one of my projects, see the below code. I trimmed some of the excess code, but that's the basic structure. Typically I would have a "context" variable and an "action" variable. The context would be matched in the index page (below) and the action would match in the included page with a similar switch structure. So I could say "index.php?context=reports&action=save" or something, and the 'reports.php' would be included, but within that included file was the input validation and MySQL code that would perform the actual save. <?php // Session start here // Functions defined here // Then include page content based on a GET or POST variable: if (isset($_REQUEST['context'])) { switch($_REQUEST['context']) { case 'logout': include 'logout.php'; break; case 'home': include 'home.php'; break; case 'personal': include 'personal.php'; break; case 'reports': include 'reports.php'; break; case 'users': include 'admin_users.php'; break; case 'quicksearch': include 'quicksearch.php'; break; case 'query': include 'view.php'; break; default: include 'home.php'; } } else { include 'home.php'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.