 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
PK

Joined: 01 Feb 2006 Posts: 19
|
Posted: Tue Jun 13, 2006 9:10 am PHP Switch error |
|
|
|
I'm deveolping a PHP site, and for one of my pages I need to have multiple things in one section, changeable from URL variables. I used a switch code to do this, but I can't figure out what is wrong with my code, the variable name I used was 'page' and it should change if its value is between 1 and 3 inclusive.
Here is the page, and this is the PHP I used for the switch section:
| Code: |
<?PHP
//Selects what goes in the right section-variable denoted in URL
Switch ($_Get["page"])
{
Case 1:
Echo "Aditional List 1";
Break;
Case 2:
Echo "Aditional List 2";
Break;
Case 3:
Echo "Aditional List 3";
Break;
Default:
Echo "Main List";
Break;
}
?>
|
Can anyone offer any help? |
|
Padaxes
Joined: 06 Apr 2006 Posts: 27
|
Posted: Tue Jun 13, 2006 3:00 pm |
|
|
|
try this
| Code: |
<?php
Switch ($page)
{
Case '1':
Echo "Aditional List 1";
Break;
Case '2':
Echo "Aditional List 2";
Break;
Case '3':
Echo "Aditional List 3";
Break;
Default:
Echo "Main List";
Break;
}
?> |
|
|
PK

Joined: 01 Feb 2006 Posts: 19
|
Posted: Wed Jun 21, 2006 8:35 am |
|
|
|
Thats fine if I have the variable declard somewere else on the page, but I wanted it to read the variable off of the URL, how would I get it to do that?
EDT:// nevermind, I got it to work using the following code:
| Code: |
<?PHP
//Selects what goes in the right section-variable denoted in URL
Switch ($_GET["page"])
{
Case '1':
Echo "Aditional List 1";
Break;
Case '2':
Echo "Aditional List 2";
Break;
Case '3':
Echo "Aditional List 3";
Break;
Default:
require ("mainlist.htm");
Break;
}
?> |
Thanks for the help. |
|
Padaxes
Joined: 06 Apr 2006 Posts: 27
|
Posted: Wed Jun 21, 2006 12:26 pm |
|
|
|
Actually my code works if its passed in by the URL, you dont HAVE to use $_GET. At least it works for me
But anyway it works for you now thats the main thing  |
|
degsy

Joined: 23 Feb 2005 Posts: 2440 Location: North East, UK
|
Posted: Wed Jun 21, 2006 12:33 pm |
|
|
|
| Padaxes wrote: |
Actually my code works if its passed in by the URL, you dont HAVE to use $_GET. At least it works for me
But anyway it works for you now thats the main thing  |
Your PHP ini file has register_globals on. Don't rely on that. Use the superglobals such as $_POST, $_GET etc. |
|
Padaxes
Joined: 06 Apr 2006 Posts: 27
|
Posted: Thu Jun 22, 2006 12:17 am |
|
|
|
| Yeah thats the one! |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|