galvin Posted January 11, 2010 Share Posted January 11, 2010 Just curious if one of these ways is better (i.e. more efficient) than the other. I have an index.php page where there is a menu across the top with 5 choices. For example, HOME | MONKEYS | CATS | DOGS | KANGAROOS. I have ALL the code for those 5 pages on that single index.php file. Now is it better to... 1. Use FORM SUBMIT BUTTONS for each menu option. So I'd have the action of the form be "index.php" and then code like this for the menu... <input type='submit' name='submit' value='HOME' ><input type='submit' name='submit' value='MONKEYS' > And then I would have IF statements to see which Submit button was clicked and show the right info accordingly. OR 2. Use appended URLs and then use GET to see which info should show, as in... <a href="index.php?page=home">HOME</a>|<a href="index.php?page=monkeys">MONKEYS</a> (etc, etc) And then have IF statements using GET to check the URL and show the right info accordingly. I'm not sure one way is better than the other, but just curious if anyone has any thoughts. Like maybe one of these processes in more server intensive than the other?? NOTE: If I use Google Analytics, I guess might help to see appended URLs to know which page got more hits, rather than just seeing info for index.php without knowing if they visited MONKEYS, or CATS or whatever. But please answer the question as if Google Analytics was not relevant. Thanks, Greg Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/ Share on other sites More sharing options...
teamatomic Posted January 11, 2010 Share Posted January 11, 2010 I would use _GET. but skip the if's $page = $_GET['page']; include(header.php); include("$page.php"); include(footer.php); But be sure to clean-up the $page value before you use it or nasty thing may happen to your site. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/#findComment-992516 Share on other sites More sharing options...
jeremy0 Posted January 11, 2010 Share Posted January 11, 2010 Personally, if you're going to do it this way then use get objects - less code, simple to handle on server code: e.g. cats, monkeys -> <a href="index.php?option=cats">Cats</a> <a href="index.php?option=monkeys">Monkeys</a> ... (server check) if ($_GET['option'] == 'cats') { //display page 1 } elseif ($_GET['option'] == 'monkeys') { //do stuff for page 2 } But personally, especially with google analytics use - why not just set up different pages for these and do the normal html links? Is there some requirement that forced you to put these in such a scripted manner? Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/#findComment-992519 Share on other sites More sharing options...
Catfish Posted January 11, 2010 Share Posted January 11, 2010 isn't it much of a much ness because the form can be submitted through GET anyway? the only difference would be the way you code/maintain the links in the html file. Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/#findComment-992613 Share on other sites More sharing options...
oni-kun Posted January 11, 2010 Share Posted January 11, 2010 I'd recommend against teamatomic's solution. But what you should do is use a database if you're looking for a serious solution, and call it through $pageid = (int)$_GET['page']; to tighten security and manage easier. If you're wanting to keep it simpler, it'd be much easier to do it in your first method. Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/#findComment-992614 Share on other sites More sharing options...
soycharliente Posted January 11, 2010 Share Posted January 11, 2010 I would use a switch statement. Define a case for each page you want to display and then a default case for when no match is made. You won't have to worry about random pages trying to be loaded. <?php $page = $_GET['page']; switch ($page) { case 'index': include 'index.html'; break; case 'about': include 'about.html'; break; case 'contact': include 'contact.html'; break; default: include 'four04.html'; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/187998-get-vs-submit-button-to-show-sections-on-one-indexphp-page/#findComment-992624 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.