Page 1 of 1

PHP query stings

Posted: Mon Jun 20, 2005 1:16 pm
by ericburnard
Hi there.

I have got the hang of using the query string function but am interested in how to use multiple querry strings (such as http://www.site.com/index.php?id=32&page=73 ).

Also i am wanting to know how to use querry stings like this

http://www.marcusnoble.co.uk/index.php?page=Props

as at the moment i can ony get them like

http://www.marcusnoble.co.uk/index.php?Props

Thanks

Eric

Posted: Mon Jun 20, 2005 1:19 pm
by Burrito
you just separate the URL vars with & then call them individually on your "action" page:

ex:

Code: Select all

<a href=&quote;actionpage.php?id=45&page=bob&quote;>here</a>

Code: Select all

echo $_GETї'id'].&quote;<br>&quote;.$_GETї'page'];

Posted: Mon Jun 20, 2005 1:30 pm
by ericburnard
Burrito wrote:you just separate the URL vars with & then call them individually on your "action" page:

ex:

Code: Select all

<a href=&quote;actionpage.php?id=45&page=bob&quote;>here</a>

Code: Select all

echo $_GETї'id'].&quote;<br>&quote;.$_GETї'page'];
ok i get whats there so far but where do i put the content i want displayed for that link?

Eric

Posted: Mon Jun 20, 2005 1:34 pm
by Burrito
that really depends on how your page/site is set up.

if you're grabbing info from a db, you could populate your link with that information, or you could use already existing url vars, or local page vars, etc.

ex:

Code: Select all

$row = mysql_fetch_assoc($result);
$somevar = $rowї'somefieldonyourtable'];
echo &quote;<a href=\&quote;actionpage.php?id=&quote;.$_GETї'id'].&quote;&page=&quote;.$somevar.&quote;\&quote;>here</a>&quote;;

Posted: Tue Jun 21, 2005 10:44 am
by ericburnard
My friend says that he uses the code

Code: Select all

$date = $_SERVERї&quote;QUERY_STRING&quote;]
to get links like

http://eric.madashatters.com/archives.php?date=may

i have played arround with it to try and get it to work although it wont :?

HELP PLEASE!!

Eric

Posted: Tue Jun 21, 2005 10:58 am
by Burrito
and so what happens when you echo $date or just echo $_SERVER['QUERY_STRING']?

you should get something like: date=may right? All that does is display any url parameters along with their values.

so say for example you had:

http://www.mydomain.com/page.php?var1=b ... var3=larry

if you echoed the $_SERVER['QUERY_STRING'] of that you'd get:

var1=bob&var2=joe&var3=larry

now if you want to just grab the values of any of those parameters, you need to use the $_GET array and list the name of the parameter as the key of the value you want to retrieve.

ex:

Code: Select all

echo $_GET['var1'];
// yields bob
the only time I ever use $_SERVER['QUERY_STRING'] is if I'm redirecting to another page but I want to remember where the user was when they were redirected (including the url params). I can then dump that value into a sesson var or a cookie or the db etc and recall it to send them back after I'm done doing whatever I want to with them.

hopefully that clears things up, if not let me know and I'll elaborate more.