Building a URL based on user input

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Building a URL based on user input

Post 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?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post 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!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Maybe its a sign :P
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post 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! :P

But I must admit deploying the pEAR framework for just this seems slightly excessive!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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&#1111;'filter']);
$query= "SELECT blah...".$filter;
This is by no means the best way, just my way :?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

No queries are passed to a new page but to the same page.
Post Reply