mjcoco Posted May 23, 2008 Share Posted May 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
smc Posted May 23, 2008 Share Posted May 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
mjcoco Posted May 23, 2008 Author Share Posted May 23, 2008 Exactly what i was looking for. THANKS!!! I guess i just wasnt thinking, i tried just adding &cat_id= $cid and it was messing up the url... but that works great. Quote Link to comment Share on other sites More sharing options...
mjcoco Posted May 24, 2008 Author Share Posted May 24, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.