Update to Search script in MySQL/PHP

September 11, 2008

Topics: Accessibility.

This is an old project, now obsolete. Links have been redacted.

I know it’s only been a month, so it’s obviously far too soon for me to be publishing any kind of a script update. However, these were things which just needed to be done.

First, I’ve greatly improved the internationalism of the script: it now operates searches on UTF-8 encoded data, so it should be great for working with any language which requires characters in that character set. Testing this kind of behavior is difficult, so if you should encounter any problems please do let me know!

Second, I improved the pagination of results. Previously, if there were 150 pages of results, you’d have to see links to every single page of the results. Granted, this can be advantageous, but it’s not really practical. In this updated version, when there are more than 10 pages of results you’ll only have links to the first page, the last page, and two pages before and after the current page. This boundary is configurable — you can offer 50 pages before and after the current, if you wish, but the default is 2.

Last, I changed the way the search query was checked before being sent to MySQL. The original version of this script used my own custom-authored regular expression to secure the request. This was probably very secure, since it functioned by only allowing certain characters rather than checking restricted characters — but it did make things such as multibyte queries pretty much impossible. So it was time to change over to a more standard method. So be it! I got what I needed out of the regular expression; it didn’t need to stay in the script.

Have something to contribute?

« Read my Comment Policy

8 Comments on “Update to Search script in MySQL/PHP”

  1. Just an update: ignore my last post, the quotes works fine online, just not locally for some reason. Thanks.

  2. Hi. I love your script and am messing around with it on my little database to help me learn more PHP (Hypertext PreProcessing). It works great, but anything with quotes or an apostrophe just stops the script, not even “0” results or an error. Any idea what it could be? I can live with the >50% of entries and the small-string denial, but if you know ways to get around those I’d listen.

  3. Thanks for all this information .. i asked some similar question on yahoo answers but it didn’t really help. thanks

  4. that’s right!

    thanks! hehe

  5. It does work, in fact – but it doesn’t automatically do wildcard searches. If you add the MySQL wildcard operator (*) at the end of a word, you’ll get the wildcard search: merlo* or pino*, for example.

  6. hi there!

    When i type (merlot or pinot), got results…ok!
    but when typing (merlo or pino), no results…
    even, merlo, merl and so on….

    is it possible to get this to work ?

    tried california, which was ok…but for (californi), got no results….is this correct ?…have one script done by myself that works like this…but i’d like to get results when people type CALIFORNIA or CALIFO or CALIFORNI …is is possible ?

    thanks a lot!

  7. Glad to help! Thanks, Alen.

  8. Dear!
    Thanks for your pagination improvement! It was one thing i was looking for