Jump to content

[SOLVED] index.php?action=search <--this using wat method?


zgkhoo

Recommended Posts

http://www.phpfreaks.com/forums/index.php?action=search <---redirect to search page

http://www.phpfreaks.com/forums/index.php?action=profile <--redirect to profile page

http://www.phpfreaks.com/forums/index.php?action=calender <---redirect to calender page

now i only know how to design php page by using eg...search.php /profile.php /calender.php

and i wanna learn the above method..

may i know how to write this method and this method called wat?

thanks....

Link to comment
Share on other sites

use a switch statement on your index.php page, like this:

<?php
	switch ($_GET['page']) {
		default:
		case "home":
			require_once ("lib/home.php");
			break;
		case "progress":
			require_once ("lib/progress.php");
			break;
		case "support":
			require_once ("lib/support.php");
                                break;
                        }

and put all the files that you require_once in a lib folder to keep it organized

 

Regards ACE

Link to comment
Share on other sites

Ok if you're willing to listen I'll explain it...

 

<?php
switch ($_GET['page']) {

    case "home";
    pageHome();
    break;

    case "contact";
    pageContact();
    break;

    case "support";
    pageSupport();
    break;

    default:
    pageHome();
    break;
                        }

function pageHome() {
    echo('I am the Homepage!');
}

function pageContact() {
    echo('I am the Contact Page');
}

function pageSupport() {
    echo('I am the Support Page');
}

?>

 

Look at the above code...

 

switch ($_GET['page']) {

 

...is the part we're looking at...that means that it will be index.php?page=

 

If we change that to...

 

switch ($_GET['section']) {

 

...then the link would instead be index.php?section=

 

Ok now the next part we're looking at is:

 

    case "home";
    pageHome();
    break;

 

So if you type ?page=home it will run the function pageHome() which I made:

 

function pageHome() {
    echo('I am the Homepage!');
}

 

For every page you have, you'll have an instance of this code:

 

    case "home";
    pageHome();
    break;

 

Say if you wanted to use the code I posted but add a "pictures" page, you'd add this:

 

    case "pictures";
    pagePictures();
    break;

 

And this:

 

function pagePictures() {
// Code to show your Pictures here...
}

 

 

...

 

    default:
    pageHome();
    break;

 

that just tells the page what to do if you type index.php or index.php?page, so if you don't supply it with a page to go to it will go to the one you specify as "default".

 

That make sense...?

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.