Jump to content

[SOLVED] $_GET


ngreenwood6

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

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.