2

I'm currently developing a table layout. The tables are using a paginator and a filter function in PHP.

All values are transmitted as GET parameters.

For example, the paginator will use &limit=20&page=5. The filter is built upon a table row in thead as input fields. What I mean is that each column has it's own input field.

Once the submit button is clicked, it will pass the data via GET to itself, so the next pageview will query/filter the data correctly.

For example, if I want to filter the postcode the url will be as following: &limit=20&page=5&postcode=5

Because I'm allowing searches like %5% to show all postcodes where 5 where the result is not limited to 5 only. It will show all data which has a 5 at any spot of the value.

However, if I want to filter the postcodes showing all results with 58, I will type in %58%. As per URL encoding, unfortunately, the URL won't be &postcode=%58% as expected. It will be &postcode=X%.

The question is whether it is somehow possible to get the correct values into the URL?

The problem lays on browser level. If I would change the URL from &postcode=X% to &postcode=%58% directly and hit enter, Chrome would translate it straight away to X%.

Maybe it's possible somehow with meta tags, http headers, or Javascript, etc.

I'm doing it via GET instead of POST because it was - apparently - simpler to integrate with the paginator.

Sorry for my bad English. Any help would be much appreciated.

Thanks a lot.

2
  • 1
    Apologise, I've should have said I'm using MySQL. Perfect, that's how I'm doing it now. Thanks for your reply! Commented Oct 20, 2017 at 5:27
  • Glad that worked! I moved the comment to an answer Commented Oct 20, 2017 at 14:38

3 Answers 3

2

You should escape the "%" sign itself (that would be "%25"). PHP should be smart enough to decode that automatically.

So &postcode=%58% should become &postcode=%2558%25, which PHP will decode so that $_GET['postcode'] is '%58%'.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply, it's a good suggestion. However, I am using the solution mentioned as a comment on my question from billrichards.
1

You should urlencode your values before inserting them into the params.

Overall though, If you are using mysql I agree with billrichards.

1 Comment

Thanks for your reply, it's a good suggestion. However, I am using the solution mentioned as a comment on my question from billrichards
0

Since you mention %% searches I assume you are using MySQL or another SQL back end to query for the data. In that case I would suggest leaving the querystring always formatted as postcode=58&page=1, and add some other parameter to indicate if it should be a %wildcard% search or exact match, and if the wildcard parameter is there, add the %% on the back end when performing the query.

1 Comment

that's the solution I've followed. However, the other answers may provide a correct way to solve it too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.