Jul 20, 2008

Simple Page With Different Parts

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Simple Page With Different Parts

apple
I want to make a simple page in php. it has 3 steps.. like ,
page.php there i say, lets go to second step.. and i want to create page.php?step=2 and there.. i say lets go to step3 and i create page.php?step=3
How i can create like that.. anyhelp please

Reply

ghostrider
try this

CODE
$step = $_GET['step'];
// This gets the step you want

switch ($step) {
case 1:
// Put your code for case 1 here
break; // Needed to tell PHP to exit the switch statement
case 2:
// Code.
break;
case 3:
// Code
break;
default:
// This code is ran if no step is run.  
break;
}



Reply

jlhaslip
You could start here with a search of the Forum, or go directly to a recent Tutorial about the switch method.

Switch Method Tutorial

There are also other Tutorials. Once you figure out the search Method, you will find lots of information here.

Reply

apple
Oh yes, that was what i was looking for.. thank you both of you guys smile.gif
QUOTE(jlhaslip @ Mar 2 2007, 12:25 AM) *
You could start here with a search of the Forum, or go directly to a recent Tutorial about the switch method.

Switch Method Tutorial

There are also other Tutorials. Once you figure out the search Method, you will find lots of information here.


Reply

saga
Recently I made my website with the same approach. One php page that will display different content depending on what the viewers want. As I was on the process on developing it I found out that the php page will become cumbersome as the content it will display will increase. In your case, when the steps reaches step20 or more. So instead of using switch() statement and encode all the information needed to display in one php page with respect to each steps (steps 1 to 20 for example) in your case you could use one instruction that will do it all:

require("file");

the above function basically will insert the content of "file" as HTML. To understand how it works we will create an example. First let say that we have a file named one which is save in the same folder with your page.php

one
CODE
<h3>This is Step 1</h3>
<?PHP
    print "\nPHP things to do in step 1";
?>


above is the content of the file one. As you notice we use the <?PHP ?> php tag. Whatever text file require() will insert it consider it as an HTML texts not PHP thus it is neccessary to use the PHP tag when adding php code.


page.php
CODE
<html>
<head>
</head>
<body>
    <?PHP
        if(isset($_GET['step']))
            require($_GET['step']);
    ?>
</body>
</html>


above is the page.php file. As you can see its pretty neat but it works fine and better than the swtich() statement.


Heres how it works:
For example we use the page.php as page.php?page=one. So what happened is the variable $_GET['step'] contains the string "one" which is basically the name of our file for the first step. In that case when we code require($_GET['step'); its just the same as require("one"); which will insert whatever content the file one. But be sure that one file is the same directory with the page.php file. But if it is not or if you want to use extensions like one.txt or one.inc use this technique:

assuming that we have a file one.inc which is saved in the folder myfolder/steps

page.php
CODE
<html>
<head>
</head>
<body>
    <?PHP
        $location = 'myfolder/steps/';
        $extension = '.inc';    //I like to use inc as extension coz it could mean include file
        if(isset($_GET['step'])){
            $file = $location . $_GET['step'] . $extension;
            require($file);
        }
    ?>
</body>
</html>



The final HTML code output of your page.php if we use it like this page.php?page=one is

CODE
<html>
<head>
</head>
<body>
<h3>This is step 1</h3>
PHP things to do in step 1
</body>
</html>


Basically becuase of the require() function whatever the content of one.inc it is inserted in the area where we called the funtionc require().

With this technique you can have as many steps you want to take. You just have to create the files two.inc, three.inc ... twenty.inc. The best thing about this is each steps instructions and data are saved in individual file which means mentaining and debugging is easy and not cumbersome. As you can see there are few codes in the page.php as opposed to swtich() statement in which you will crease a list of case value:.

 

 

 


Reply

atarplus
I prefer the switch solution, sometimes we get so many files that it is very difficult to remember the relation between all files.

Using the switch solution you can put the different cases in different functions and so this is a lot easier to handle.

If you want to use the include solution, think well of your naming strategy so you know the relationship between the files. The included files should be in a different directory.

Good luck !!!! tongue.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : parts

  1. Help In 2 Parts - (2)



Looking for simple, page, parts

Searching Video's for simple, page, parts
advertisement



Simple Page With Different Parts



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE