I need Help with Page Navigation and passing Variables

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
m7med
Forum Newbie
Posts: 5
Joined: Sat May 05, 2007 3:27 pm

I need Help with Page Navigation and passing Variables

Post by m7med »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
hey guys i am trying to write a php code, and i have a problem.

i used

Code: Select all

if (!$action)
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

Code: Select all

switch
it doesn't work.

any suggestions ??
Last edited by m7med on Mon May 07, 2007 12:56 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post 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:

Code: Select all

$action = $_GET['action'];
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 :wink:
m7med
Forum Newbie
Posts: 5
Joined: Sat May 05, 2007 3:27 pm

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Descriptive subjects

Post by feyd »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
m7med
Forum Newbie
Posts: 5
Joined: Sat May 05, 2007 3:27 pm

Post by m7med »

any suggestions ?
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post 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
Post Reply