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
https://forums.phpfreaks.com/topic/72162-solved-indexphpactionsearch/
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

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...?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.