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.
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%'.
You should urlencode your values before inserting them into the params.
Overall though, If you are using mysql I agree with billrichards.
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.
Related
I have an issue with a Wordpress premium theme and MySQL database. The value in the database box looks like this:
a:1{i:0;a:4{s:4:"name";s:9:"Trailer";s:6:"select";s:6:"iframe";s:6:"idioma";s:2:"en";s:3:"url";s:82:"https://youtube.com/sample.mp4
";}}
When I edit the YouTube link value to something else, the entire data in this box disappears on the live Wordpress page, although it is visible in the database even after refresh. I have no idea why this happens and how I can keep it from happening.
EDIT:
After i tried editing other values like post_title etc it just wont update the values at all on the live WP page.Why im doing this is because i need to add and edit mass amounts of data easily with scripts.
The string you are displaying is coming from PHP serialize. This is a way for PHP to stringify any value for later usage.
If you want to mass modify those values, your best bet is to create a PHP script that fetch the data, unserializes it, make change directly to the PHP variable it created, and serialize again to put to database.
If you want to play with the string directly, you will need to make sure you are careful.
The main reason why changing the URL of the youtube video doesn't work is because you might not be changing the string declaration too.
s:82:"https://youtube.com/sample.mp4";
This is invalid. It is split into 3 parts, using :. Type:Length:Value. So it is a string of length 82, yet you provide a 30 character string.
If you turn on NOTICE in PHP you will certainly see the errors about it.
EDIT:
After tinkering a bit on PHPFiddle.org I came up with a clean string from the one you gave, which has numerous flaws...
a:1:{i:0;a:4:{s:4:"name";s:7:"Trailer";s:6:"select";s:6:"iframe";s:6:"idioma";s:2:"en";s:3:"url";s:30:"https://youtube.com/sample.mp4";}}
Note that I changed the Length values in 2 parts, and added 2 semi-colon :
From what I understand it is possible to get query strings and clean up the url afterwards.
I basically want to send a user a link containing many types of data to build up a special page for them and afterwards clean up the url to hide the mess. I would mainly use the parameters to load certain products etc.
What would be the best way going about this? And is this even possible?
Thank you.
My thought is use two functions/links instead for this. First function/link will be that user will click and store those values in a session and transfer it to other neat URL .
I'm trying to sort out an issue with foreign characters and matching those to a database value.
I've managed to get a match out of the database query as I wanted but now I've run into a different problem and simply don't know why what's happening is happening.
On all pages throughout the site there is a header include which has a input field to search the site.
<form action="/search.php" method="get"><input name="q" type="text" />etc...
My problem query string was this grønhøj. When I enter this string into the input form on the homepage I get taken to the search page with the url like so: search.php?q=gr%F8nh%F8j which doesn't work at the moment.
However if I then re-enter that same search query into the header input when im on the search page the page reloads except the url now looks like this: search.php?q=grønhøj which does work.
If the resulting url would remain the same all the time, then I'd not have a problem, but because its inconsistent I don't know how to provide solutions to both possible versions of the query string.
So I guess I have 2 questions.
1) Why does the url not stay the same when it's using the exact same form to submit the string?
2) how can I manipulate both versions (or stop the different pages resulting in different urls) of the url so that the resulting string is consistent regardless of which version of the url I get?
UPDATE: I found a function to detect utf8 encoding Here which allowed me to switch how I handle the url string depending on which version of the url I get, so now my main issue is fixed.
I would still however like to understand why I get the 2 different url variables from the different pages even though the form is a consistent include across the site. Any ideas?
One way you can solve this issue, is to always decode the query string using urldecode() and then forcefully use urlencode() on it again. This way, if the initial query string was url encoded or decoded, no matter what, it will go through decoding and encoding process again, which will result in the same final query string.
Manual - urlencode
Manual - urldecode
I have a list of strings (names) which I would like to match to the database containing the same or variances of these names.
For each of the strings I want to match I can query the database, but this doesn’t seems to be efficient since the database is a fix set of names.
I was wondering if it was possible to have this match being done within PHP. I can use the levenshtein function in PHP, but I was wondering if there is anything more efficient.
The example I want to get to. On the left are all the strings I want to see if I have this in the database (or a small variance). Next to each I would like to have a pull down list containing the options that match closely.
String 1 – pull down
String 2 – pull down
String 3 – pull down
What is the best approach to this? I have about 500-1000 strings for which I would like to get a suggestion/pull down menu.
With kind regards
Ralf
Perhaps have a look at MySQL's full text search feature. I found this article on DevZone: http://devzone.zend.com/26/using-mysql-full-text-searching/
If you want to do it client-side, jQuery UI Autocomplete is what you want. Not only that is very easy to configure it for your needs, but you can do it with only 1 query that would get all the strings and save it into a local list, the jQuery Autocomplete data source.
You can then register an onkeyup event for an input and the jQuery plugin will query the existing cached datasource(no more pressure for your server).
Check it out:
http://jqueryui.com/autocomplete/
I m building a small search script for my website. I need to send data by get method because by POST it will get real messy as I have to show many pages of search results.
So, My question is Can I use get method directly? means do i need to encode url or any other thing ??
I have checked it in modern browsers. It works just fine..
Thanks
Edit:
Urlencode is used when puting variables in url.
I am submitting my search form with method='get' Then I get variable and perform search query and make new page links with variable data.
- Length,Size is not a prob.
U people suggesting I should use urlencode func. while making new links only ???
You can and should use urlencode() on data that possibly contains spaces and other URL-unfriendly characters.
http://php.net/manual/en/function.urlencode.php
You need to URL Encode the parameters on the URL eg http://www.example.com/MyScript.php?MyVariable=%3FSome%20thing%3F.
Be aware that there's a limit to how much data can be sent via GET - more restrictive on older browsers. If I remember correctly, IE6 has a limit of 1024 characters in the URL so if you think you're going to go over that, consider using POST or you may exclude some users.
You should use urlencode($variable) (Link) before sending the variable (even though the browser usually takes care of this) and urldecode ($variable) (Link) after receiving it, this way you can be sure special chars will be treated correctly.