PDA

View Full Version : domain.com/index.php?section=1



rajiv
July 26th, 2002, 02:39
I want to do something like this

domain.com/index.php?section=1 or any other number

I think I read somewhere about doing it but forgot the link....someone please help!

bigperm
July 26th, 2002, 02:45
There are a bazillion threads about this.

nag
July 26th, 2002, 02:51
domain.com/index.php?section=1
When you call this line script named ""index.php"" changes the value of variable section and assign it 1
thus if you have index.php something like this


<?php
include("$section.php");
?>
This would include section 1.php file.
Generally you can do lots of other things by it check it if you have index.php as


<?php
print("Welcome $name");
?>
then if you call

index.php?name=rajiv

this will display Welcome rajiv

or
index.php?name=visitor

would produce
Welcome visitor

One thing else you can pass as many values as you want like

index.php?section=1?cat=3

This would change the value of section to 1 and cat to 3.:) :) :)

nag
July 26th, 2002, 02:55
Originally posted by bigperm
There are a bazillion threads about this.
This means that if someone ask for this question and he/she do not know we should not answer it:confused: :confused:
By the way I have asked the same question on this forum in past and you people told me to search the forum??????

spork
July 26th, 2002, 06:10
Originally posted by nag

This means that if someone ask for this question and he/she do not know we should not answer it:confused: :confused:
By the way I have asked the same question on this forum in past and you people told me to search the forum??????

nah, but by telling someone there already are several threads about a certain subject the user can be expected to search the forum to find his answer... you get tired of answering the same question over and over again...

but then again, for something as simple as this it really isnīt too much trouble to type out some code...

Index.php


<?php
if ($section == "1") {
include('section1.php');
} elseif ($section == "2") {
include('section2.php');
} else {
include('default.php');
}
?>

keith
July 26th, 2002, 20:36
to save on lots of coding for lots of sections, make a directory with all your section files [ie: links.php, ads.php, homepage.php, error.php, etc...]
<?

if (!$section) {
include("homepage.php");
}

elseif(file_exists("$section.php")) {
include("$section.php");
}

else {
include("error.php");
}

?>that'll handle an unlimited amount of sections without having to tamper with the code, just upload a new section file in the right directory.

The Red Guy
July 27th, 2002, 08:29
<?php
if ($section == "1" && page == 1) {
include('section1.php');
} elseif ($section == "2") {
include('section2.php');
} else {
include('default.php');
}
?>

That'll make index.php?section=1&page=1 thingy. I learnt it here. ;)