Page 1 of 1
I need Help with Page Navigation and passing Variables
Posted: Sat May 05, 2007 3:31 pm
by m7med
hey guys i am trying to write a php code, and i have a problem.
i used
to navigate through pages but i noticed that the code is not going to work if i don't put the php.ini file in the same folder..
so i used switch instead and it worked but the problem is i have links to pass variables from one page to another and with
it doesn't work.
any suggestions ??
Posted: Sat May 05, 2007 6:35 pm
by Chris Corbyn
You completely lost me. I'm taking a mssively large stab in the dark but are you do the "if" to see if $action exists, or to see if its value is true? You should be using isset() for the former.
Posted: Sun May 06, 2007 1:03 am
by Z3RO21
I love stabbing at the dark also! I take it you are try to do a page navigation system.
First of all you would want to get the variable from the url (at least that is what I am guessing you are doing) and you would use something like this:
And then you would use a switch structure to handle pages / actions for example:
Code: Select all
switch ($action) {
case 'a':
echo 'action a';
break;
case 'b':
echo 'action b';
break;
case 'c':
echo 'action c';
break;
default:
//this is the default action, this could be used as the error catcher
echo 'no action specified!';
}
there is my stab

Posted: Sun May 06, 2007 1:12 am
by m7med
a better way to explain is to give an example so here is my example.
this page would display links and when you click the a link it would show another page from the same file and pass the variable (name)
Code: Select all
if (!$action){
echo"<a href='mypage.php?action=first_link&&name=john'>First Link</a>";
}
if ($action=="first_link"){
echo" The name is $name ";
}
so this code would not work if i don't put the php.ini file in my folder so i tried to use switch this way
Code: Select all
switch($_SERVER['QUERY_STRING']) {
case 'first_link'':
echo "The name is $name";
break;
default:
echo"<a href='mypage.php?first_link&&name=John'>First Link</a>";
}
but the problem is it doest show the first link page when i click on the link!
so what is wrong here ?
Descriptive subjects
Posted: Sun May 06, 2007 11:53 pm
by feyd
Posted: Mon May 07, 2007 3:30 pm
by m7med
any suggestions ?
Posted: Mon May 07, 2007 9:22 pm
by Z3RO21
m7med wrote:
Code: Select all
switch($_SERVER['QUERY_STRING']) {
case 'first_link'':
echo "The name is $name";
break;
default:
echo"<a href='mypage.php?first_link&&name=John'>First Link</a>";
}
Have you noted the error?
case 'first_link'': do you see the double single quotes at the end? Try it with out that and why you using $_SERVER['QUERY_STRING'] look at my example and use a variable either in the post or get arrays