Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Simple Page With Different Parts
apple
post Mar 1 2007, 10:07 PM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 31
Joined: 9-August 06
Member No.: 28,049



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
Go to the top of the page
 
+Quote Post
ghostrider
post Mar 1 2007, 10:19 PM
Post #2


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



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


Go to the top of the page
 
+Quote Post
jlhaslip
post Mar 1 2007, 10:25 PM
Post #3


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,994
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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.
Go to the top of the page
 
+Quote Post
apple
post Mar 1 2007, 10:39 PM
Post #4


Newbie [Level 2]
**

Group: Members
Posts: 31
Joined: 9-August 06
Member No.: 28,049



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.

Go to the top of the page
 
+Quote Post
saga
post Mar 2 2007, 03:03 AM
Post #5


Premium Member
********

Group: Members
Posts: 165
Joined: 12-September 05
Member No.: 11,777



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

This post has been edited by saga: Mar 2 2007, 03:04 AM
Go to the top of the page
 
+Quote Post
atarplus
post Mar 3 2007, 10:20 AM
Post #6


Newbie
*

Group: Members
Posts: 6
Joined: 2-March 07
Member No.: 39,459



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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Help In 2 Parts(2)


 



- Lo-Fi Version Time is now: 6th September 2008 - 04:47 PM