Jump to content

Question over parameter passing


mjcoco

Recommended Posts

I know this isnt the best question or anything but basically i need help with passing a second variable.  As in www.example.com?id=32  and seperately have it to where it displays a new list of links and when they click on that it will add in &cat_id=14 etc

 

Basically its like narrowing a search click the first link that narrows it down with the id's=32 then then on the next page it will have new links to narrow it down even further.  I have it to where it does the first, but im not sure how to do the latter (&cat_id=14)

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/106879-question-over-parameter-passing/
Share on other sites

I'm not sure if I understand your question entirely. What I think you're saying is you want to continue to redefine a URL. As in, the user visits http://example.com clicks a link that brings them to http://example.com?id=NUM, that page displays links that are http://example.com?id=NUM&cat_id=1, http://example.com?id=NUM&cat_id=2, etc.

 

This you just have to create the links to update to the variable. You can do this a number of ways.

 

The most straight forward is hard coding the variable in:

 

<?php

$myDomain = "http://example.com"
$myLink = $myDomain . "?id=" . $_REQUEST['id'] . "&cat_id=1";
$myLink2 = $myDomain . "?id=" . $_REQUEST['id'] . "&cat_id=2";

?>

 

The other way is to grab the current page. Know these predefined PHP variables:

 

$_SERVER['PHP_SELF'] :: If the PHP you are using is at http://example.com/apples/oranges/banana.php this variable will return /apples/oranges/banana.php.

 

$_SERVER['QUERY_STRING'] :: This will return all the attaches to the URL. For example, if you went to http://example.com/myphp.php?id=apples&cat=oranges this variable will return ?id=apples&cat=oranges.

 

<?php

$myDomain = "http://example.com"; //There is a predefined variable for this too but it slips me at the moment

$myLink = $myDomain . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING'] . "&cat_id=1";
$myLink2 = $myDomain . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING'] . "&cat_id=2";

?>

 

Hope this helps.

Another question.

 

Say i am at http://www.example.com/view.php?id=1&dept=2&cat_id=5

 

And i wanted to make it to where i can co back from what has been selected and take out &dept=2

making it = http://www.example.com/view.php?id=1&cat_id=5

 

Is there a query that i can go about doing that or do i just have to rebuild the entire url?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.