Jump to content

GET vs SUBMIT Button to show sections on one index.php page?


galvin

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.