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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.