Help with Dynamic Subpages! :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Achilles_Force
Forum Newbie
Posts: 9
Joined: Wed Feb 06, 2008 7:17 pm

Help with Dynamic Subpages! :)

Post by Achilles_Force »

Cant get the following to work

Code: Select all

<h1>Page title</h1>
<p>Select:
<a href="index.php?y=subpages">back</a> |
<a href="index.php?y=subpages&x=1">link 1</a> |
<a href="index.php?y=subpages&x=2">link 2</a> |
<a href="index.php?y=subpages&x=3">link 3</a> |
</p>
<? if(!$x) { ?>
000000<!-- main content should appear here :\ -->
<? } elseif ($x == "1") { ?>
111111<!-- Content for x1 SHOULD be here -->
<? } elseif ($x == "2") { ?>
222222<!-- Content for x2 SHOULD be here -->
<? } elseif ($x == "3") { ?>
33333<!-- Content for x3 SHOULD be here -->
<? } ?>
PLEASE some help. THANKS! :)
Last edited by Achilles_Force on Thu Feb 07, 2008 6:50 pm, edited 1 time in total.
Festy
Forum Commoner
Posts: 28
Joined: Wed Jan 30, 2008 10:01 pm

Re: Help with Dynamic Subpages! :)

Post by Festy »

What error are you getting exactly?
Achilles_Force
Forum Newbie
Posts: 9
Joined: Wed Feb 06, 2008 7:17 pm

Re: Help with Dynamic Subpages! :)

Post by Achilles_Force »

not an "error". it just wont work.. :\ (I run php5)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Help with Dynamic Subpages! :)

Post by VladSun »

Place this at the very beginning of your code:

Code: Select all

$x = intval($_GET['x']);
This is because register_globals is set to Off in your php.ini... and it should be!
Last edited by VladSun on Thu Feb 07, 2008 6:20 pm, edited 2 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
Achilles_Force
Forum Newbie
Posts: 9
Joined: Wed Feb 06, 2008 7:17 pm

Re: Help with Dynamic Subpages! :)

Post by Achilles_Force »

Code: Select all

<h1>Page title</h1>
<p>Select:
<a href="index.php?y=subpages">back</a> |
<a href="index.php?y=subpages&x=1">link 1</a> |
<a href="index.php?y=subpages&x=2">link 2</a> |
<a href="index.php?y=subpages&x=3">link 3</a> |
</p>
<? if(!$x) { ?>
$x = intval($_GET['x']);
000000<!-- main content should appear here :\ -->
<? } elseif ($x == "1") { ?>
111111<!-- Content for x1 SHOULD be here -->
<? } elseif ($x == "2") { ?>
222222<!-- Content for x2 SHOULD be here -->
<? } elseif ($x == "3") { ?>
33333<!-- Content for x3 SHOULD be here -->
<? } ?>
Like that? :S
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Help with Dynamic Subpages! :)

Post by VladSun »

VladSun wrote:Place this at the very beginning of your code:
There are 10 types of people in this world, those who understand binary and those who don't
Achilles_Force
Forum Newbie
Posts: 9
Joined: Wed Feb 06, 2008 7:17 pm

Re: Help with Dynamic Subpages! :)

Post by Achilles_Force »

Code: Select all

<h1>Page title</h1>
<p>Select:
<a href="index.php?y=subpages">back</a> |
<a href="index.php?y=subpages&x=1">link 1</a> |
<a href="index.php?y=subpages&x=2">link 2</a> |
<a href="index.php?y=subpages&x=3">link 3</a> |
</p>
<? $x = intval($_GET['x']); if(!$x) { ?>
000000<!-- main content should appear here :\ -->
<? } elseif ($x == "1") { ?>
111111<!-- Content for x1 SHOULD be here -->
<? } elseif ($x == "2") { ?>
222222<!-- Content for x2 SHOULD be here -->
<? } elseif ($x == "3") { ?>
33333<!-- Content for x3 SHOULD be here -->
<? } ?>
uhh.. Cant you just post an example? ^_^"
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with Dynamic Subpages! :)

Post by Christopher »

The general concept is that you don't want to check $x (i.e., if (!$x) ) before you have assigned a value to $x.

Code: Select all

 
<?php
$x = intval($_GET['x']);
if(!$x) {
(#10850)
Achilles_Force
Forum Newbie
Posts: 9
Joined: Wed Feb 06, 2008 7:17 pm

Re: Help with Dynamic Subpages! :)

Post by Achilles_Force »

Ah, it works now. Awesome. Thanks guys! :)
Post Reply