ISO Image
Creator


Merge 2 scripts
Jan 1 2006, 07:57 AM

Helpful Member
![]()
Group: Members
Posts: 78
Joined: 23-October 04
Member No.: 23,034
India
![]()
I want to know how to merge 2 php scripts into one.
This is script no 1
<?php
echo "hello php1"
?>
This is script no 2
<?php
echo "hello php2"
?>
I want to put these into one .php file .
How will u call each script, so that either hello php1 or hello php2 is displayed.
Not both.
something like
http://localhost/merged.php?action=1
or
http://localhost/merged.php?action=2
i hope i could explain. ![]()
Thanks N Happy new year to all.
May this new year be a blessed year with peace n good health.
Jan 2 2006, 06:54 AM
![]()
Themer
![]()
Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
United Kingdom
![]()
You can do this one of two ways and I'll explain as I go along.
To do what you ask in php you will need what is called a switch. The switch needs two things: what it will be switched by and what to do when it is switched. For example:
// $_GET['action'] means that in the url, if someone puts action=something the switch will do something
switch($_GET['action']) {
//next we need the cases, or what we want the switch to do when someone puts action=something
case 'number1': // this will let you use action=number1
// here you could either include a file (for bigger projects) or just echo a statement
include('number1.php');
// or
echo 'hello php1';
// statements must end with the break; command
break;
case 'number2':
echo 'hello php2';
break;
// just close the switch and php
}
?>
Hope this helps
btw. Brandon, what happened to that topic of mine? It was huge
-Mackins
This post has been edited by Mackins: Jan 2 2006, 07:41 AM
Jan 5 2006, 09:32 AM

Helpful Member
![]()
Group: Members
Posts: 78
Joined: 23-October 04
Member No.: 23,034
India
![]()
<?php
script1
script2
?>
Just any example. Put 2 scripts in one php file, and what wil u type in address bar to execute script 1 or script 2.
Jan 5 2006, 11:43 AM
![]()
Themer
![]()
Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
United Kingdom
![]()
<?php
switch($_GET['do']) {
case 'say_hello':
include 'say_hello.php';
break;
case 'say_goodbye':
include 'say_goodbye.php';
break;
}
?>
//say_hello.php
<?php
echo 'hello';
?>
//say_goodbye.php
<?php
echo 'goodbye';
?>
for that you would need to put in 'index.php?do=say_hello' and in the browser 'hello' would be outputted. And the same for goodbye: 'index.php?do=say_goodbye'.
-Mackins


Lo-Fi Version
Time is now: 23rd May 2012 - 11:46 AM
![]()
Webber Enhanced skin created by Im4eversmart of RuneHQ.