Forum Moderators: coopster

Message Too Old, No Replies

Using querystrings

         

moonbather

1:32 am on Aug 31, 2003 (gmt 0)

10+ Year Member



Hello,

I modified an example (called demoquery.php) at a French language site

[asp-php.net...]

which I think is designed to deliver different webpage content from within one file (depending on the value of the querystring). I couldn't get the example to work, so I tried changing it a little, eg using

<?php
[2]<?[/2]


<A href="?page=1">Page 1</A> -
<A href="?page=2">Page 2</A> -
<A href="?page=3">Page 3</A>
</div><hr>
<?php 
$page=$_GET['page'];
switch($page) {
     case "1" :?>
page 1
<?php break; case "2" :?>
page 2
<?php break; case "3" :?>
page 3
<?php break; default:?>
default page
<?php }?>
but still no luck. So I wondered if anyone had any ideas? Thank you.

jamie

10:24 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi moonbather,

the examply you posted worked perfectly on my machine, running win2k/apache 2/php 4.2/mysql 4

so the code is correct.

you might have an older version of php, so try $HTTP_GET_VARS['page'] instead of $_GET['page']

you might like to read the manual on superglobals [es.php.net]

the user comments are useful

good luck

moonbather

2:26 pm on Sep 3, 2003 (gmt 0)

10+ Year Member



Thanks for the information, jamie. I'm going to have to study this globals palaver.

vincevincevince

4:43 pm on Sep 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



as above, but also note you should not just put?page=X in the href destination - it is essential to use $PHP_SELF

<A href="<?php echo $PHP_SELF;?>?page=1">Page?</A>?