Update to Search script in MySQL/PHP

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.

Long-awaited update to PHP/MySQL poll

It didn’t quite take 2 years, at least. But very, very close. The last release of this script was May 25th, 2006 — so I made it just under the wire. But this is also a bit more than just a script update. In fact, this is a complete overhaul. I’m not certain that there’s actually a single line in the poll script which is the same as the previous version.

This was necessary; because the previous version was, in a word, pretty lousy. It may have acted as a decent jumping off point for some beginning programmers to code their own; but, on the whole, it was not a sophisticated script, and it was nothing like developer-friendly.

This new version, leveraging the power of Google’s Chart API and some clever scripting by Christian Heilmann provides a better end result with fewer potential problems for the user.

I’ve vastly increased the flexibility of the script — which once could only support a fixed 2 – 5 options in a single question — to provide support for any number of questions with any number of options, customizable at the question level. I don’t anticipate that anybody will be authoring 100 question polls with this…but they could, in theory.

And, to cap it all off, I’ve added an administrative interface which allows users to perform most of their basic management needs without needing to crawl into the database. Hopefully, it won’t prove to be too buggy.

Are there likely to be bugs in this? Yes! So, if you download this and try it out, please let me know what you notice. I caught quite a few; but I think it’s safe to say that there are a few left in there.

And by “a few,” I mean “actually, there could be a lot of ‘em.”

Check it out or download the package now.

What does a “free script” need to provide?

I received an interesting comment from my contact form the other day. I don’t need to respond to it, as the sender left a clearly false email address as their response address, but I do feel that it poses an interesting question for me.

This is the message in its entirety:

Dude how come your example poll have this amazing format, cool graphics, and when I download and installed yours, looks like SHIT?

I mean, thanks for doing this and all that, but come on, you are showing a FALSE example on your web site.

The example poll referred to is this: an example installation of a free MySQL/PHP polling script available on my website. Now, I find it hard to believe that anybody actually thinks of that example as having “this amazing format, cool graphics,” but that’s not really the point: the question is what a “free script” should be expected to include.

This person obviously expected a fully-realized, designed installation. What I provided was nothing but raw HTML and PHP scripting. No “out of the box” styling at all. This is what I generally desire out of a script: if it has a few hooks for CSS and semantic code, that’s great!

I can certainly agree that if you want something you offer to really become a major player in the world of popular downloads, you’ll need to put in a fair amount of work in providing easy template styling, etc. But I hardly think that should be expected for a simple web site add-on.

It leaves me curious: when you download a script, what do you expect of it?

Easy PHP Photo Gallery

Updated 2/6/2010 — Read more below!

There are a lot of PHP photo gallery scripts out there. I know; because I went looking for one some time ago, and found myself barraged with Javascript, AJAX, and complicated installations. I didn’t want any of those things, so in the end I just wrote one for myself — and this is the end result. Download the ZIP package.

It’s not a complicated script, and it doesn’t do a whole lot for you: but, assuming you’re running on Linux with PHP, it’ll be incredibly easy for you to install and configure. View the sample installation.

What’s in the Package?

There are six main files included in this zip package (Version 1.2):

  1. gallery.php — the photo gallery script. Now contained in functions.php.
  2. index.php — the home file which includes the gallery script and contains configuration info.Configuration now in separate file; gallery files now contain only a few gallery-specific variables. You can copy this page to create additional galleries just by saving it with a new name and changing the configuration information. test.php is a second example referencing a separate gallery, to demonstrate the multiple gallery features.
  3. titles.txt — a simple text file which uses pipe-separated fields to indicate the image name, an image description, and an alt text option.
  4. title.php — a script which provides a unique title element for each image in the gallery. Now contained in functions.php.
  5. basic_styles.css — a very basic stylesheet so that your default photo gallery doesn’t look too boring. Warning: no attempt whatsoever has been made to test these styles outside of Firefox.
  6. readme.txt — installation instructions

I’ve also supplied a (very) small gallery of images for the included gallery.

What does the script do?

This is pretty straightforward. The configuration information you’ll send to the script provides the title of the gallery, the relative path to your images folder, and the name of your text file containing the image information. Using this information, the gallery script creates a page containing (in order):

  1. Navigation links to move between the previous and next images in the gallery. The sequence is the order in which you’ve listed the images in your text file. The navigation is circular, so in the initial position the previous link will send you to the last image in the gallery.
  2. A full size image with a caption. The caption is the second field in your text file.
  3. An unordered list of thumbnail images in the gallery. Again, the order is from the text file. In the default styling, the list is displayed as a panel of images rather than as a list. Each image is a link to the full sized image within the gallery.

The script does NOT automatically generate your thumbnail images. Sure, I could have done that — but my feeling is that manually creating thumbnail images will usually be more aesthetically pleasing. My preference is to create 80×80 square thumbnails cropped from the image. The tiling effect of the unordered list is much more effective with square thumbnails; and the ability to choose a particular section of the image for the thumbnail is much nicer than whatever programmatically selected truncation might have done.

Some Small Recommendations

The script allows the ability to use an alt text on your images. It also provides a description which can be used to caption the images in a paragraph either over or under the image. To me, it’s redundant to provide both descriptive text associated with the image AND a descriptive alt attribute. Therefore, I’ve also provided the option to turn off alt text in the full sized images. The default settings are what I’d recommend: visible descriptions enabled for the full size image, alt attributes left blank, and alt attributes enabled for all thumbnails.

I also recommend keeping your alt attributes short and to the point. The reason for having separate descriptions and alt attributes is because they serve different purposes: don’t try and use the description field as an alt attribute and don’t try and use the alt field for a description!

There’s nothing fancy about this script. Really — I mean it. It’s down and dirty “make me a photo gallery” programming. Use at your own risk!

Changes as of 2/6/2010

  • Improved pagination feature, adding a control to set the number of visible page links at a time.
  • Simplified support for multiple galleries.
  • Generate a list of available photo galleries.
  • Navigate through multiple galleries continuously.
  • Separated most configuration options into an external file, rather than configuring the same options for every gallery.

These changes are very substantial to the core code; although the majority of the actual code has remained the same, the structure of the code usage has been significantly revised. See the readme.txt for details on usage.

On the whole, this should be easier than ever before; although you may be in for a little work if you’re trying to revise.

Note: The basic output (HTML, unique ID’s, classes, etc.) is unchanged. The format of the titles.txt file is unchanged. The only changes are in the addition of new features, in the way configuration options are set up, and in the way information is output from the scripts.

Page 1 of 11

Return to Top