IPB

ISO Image Creator

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Merge 2 scripts
Cool Surfer
post Jan 1 2006, 07:57 AM
Post #1


Helpful Member
Group Icon

Group: Members
Posts: 78
Joined: 23-October 04
Member No.: 23,034
 India


Hi guys

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. smile.gif
Thanks N Happy new year to all.
May this new year be a blessed year with peace n good health. online2long.gif
Go to the top of the page
 
+Quote Post
Mackins
post Jan 2 2006, 06:54 AM
Post #2


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


I remember a long time ago, I asked the same question to Brandon. biggrin.gif

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:
CODE
<?php
// $_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 wink.gif

btw. Brandon, what happened to that topic of mine? It was huge biggrin.gif

-Mackins happy.gif

This post has been edited by Mackins: Jan 2 2006, 07:41 AM
Go to the top of the page
 
+Quote Post
Cool Surfer
post Jan 5 2006, 09:32 AM
Post #3


Helpful Member
Group Icon

Group: Members
Posts: 78
Joined: 23-October 04
Member No.: 23,034
 India


ok thanks mac, can u make a script for eg
<?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.
Go to the top of the page
 
+Quote Post
Mackins
post Jan 5 2006, 11:43 AM
Post #4


Themer
Group Icon

Group: Members
Posts: 120
Joined: 17-March 05
From: England
Member No.: 29,841
 United Kingdom


Well usually, you don't put the scripts in the same file, you just put includes towards the files that have already been made. You would only put them in the same file if you were using OOP (Object Oriented Programming). Anyway, an example of what you asked:
CODE
//index.php
<?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 blink.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2012 - 11:46 AM

  Page top

Webber Enhanced skin created by Im4eversmart of RuneHQ.

  Privacy Policy 1 2 3 4 5

IPS Driver Error

IPS Driver Error

There appears to be an error with the database.
You can try to refresh the page by clicking here