Page 1 of 1
Building a URL based on user input
Posted: Mon Nov 29, 2004 8:05 am
by hairyjim
Hi.
Im a bit stuck on how to go about this and require advice on how best to go about doing the following:
Basically I have an option to filter the records on my screen and accomplish this by the use of a list/menu item and button that posts data to the same page.
Now the page also has pagination, so the user could choose to view page 2, 3 etc.
So my question is how do I go about building the URL for any page links on this page?
Posted: Mon Nov 29, 2004 9:21 am
by kettle_drum
Take the query string from the url and then regex it to get what you want. Or loop through all the $_GET items and make a string from the values that you want. You just need to filter it until your left with what you want.
Posted: Mon Nov 29, 2004 9:29 am
by hairyjim
It would seem that PHP5 has a new function http_build_query that would do exactly what I am after
Unfortunatly I have not upgraded to PHP 5
BAH!
Posted: Mon Nov 29, 2004 9:31 am
by kettle_drum
Maybe its a sign

Posted: Mon Nov 29, 2004 9:53 am
by hairyjim
Is PHP 5 recommend for live website usage yet?
Last time I used it and upgraded my site in the test environment I got no end of IIS crashes.
Perhaps I give it another go....
Oh just by luck I came across a PEAR package that allows pre PHP 5 users to get some of the new PHP 5 functions inc. the http_build_query!
But I must admit deploying the pEAR framework for just this seems slightly excessive!
Posted: Mon Nov 29, 2004 11:34 am
by xisle
It would be quicker to pass the query string as a hidden value to the next page.
In the case of a link, I generally base64_encode() the dynamic piece of the query and pass it on to the next page of results.
Code: Select all
$filter="&& filter='foo' && page='whatever'";
$enc_filter = base64_encode($filter);
<a href=page.php?filter=".$enc_filter.">bar</a>";
decode it later...
Code: Select all
$filter=base64_decode($_GETї'filter']);
$query= "SELECT blah...".$filter;
This is by no means the best way, just my way

Posted: Mon Nov 29, 2004 11:42 am
by Maugrim_The_Reaper
I hope no one's suggesting we pass DB queries across a url - what would be scriptkiddies think
Go with $_GET, or send your required data in an encoded serialised form - which might shorten the GET searching on the other end...
Posted: Wed Dec 01, 2004 3:23 am
by hairyjim
No queries are passed to a new page but to the same page.