Page 1 of 1

Help with Dynamic Subpages! :)

Posted: Wed Feb 06, 2008 8:30 pm
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! :)

Re: Help with Dynamic Subpages! :)

Posted: Wed Feb 06, 2008 11:11 pm
by Festy
What error are you getting exactly?

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 4:21 pm
by Achilles_Force
not an "error". it just wont work.. :\ (I run php5)

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 4:26 pm
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!

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 6:14 pm
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

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 6:20 pm
by VladSun
VladSun wrote:Place this at the very beginning of your code:

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 6:23 pm
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? ^_^"

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 6:30 pm
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) {

Re: Help with Dynamic Subpages! :)

Posted: Thu Feb 07, 2008 6:50 pm
by Achilles_Force
Ah, it works now. Awesome. Thanks guys! :)