Jump to content

Recommended Posts

I understand how to put something into the url through get

 

<a href="index.php?sort=desc">Descending</a>

 

The part I dont get is how do I make it universal so that I dont have to know what is going to be there already. For example if I want to add a page number to the end of this row i would do it like this:

 

<a href="index.php?sort=desc&page=1">Descending</a>

 

Now say for instance I didn't know what the url was going to be other than the fact that it was going to be index.php. How would I go about doing that? And if it was the first variable it would be with a ? instead of the & how can I make it know that it is going to be that?  Any help or links are appreciated. And please can someone make it easy to understand because I am a noob.

Link to comment
https://forums.phpfreaks.com/topic/128222-solved-_get/
Share on other sites

to get the QUERY_STRING use

$_SERVER['QUERY_STRING']

or each key/value use

foreach($_GET as $K => $V)
{
echo "Key:$K = $V<br>";
}

 

to append to the existing URL

try

$Q= (!empty($_SERVER['QUERY_STRING'])?"?":$_SERVER['QUERY_STRING']."&";

//add SORT=ASC
echo $Q."SORT=ASC";

Link to comment
https://forums.phpfreaks.com/topic/128222-solved-_get/#findComment-664077
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.