Online Demo
Essential Platform Requirements
- PHP
- MySql
- Database and a table with a text field or varchar field
Tutorial Notes
Creating a new database and table seemed a lot of work just to show a demo with content that would only be used once! I opted to use:
- your very own database table content.
- with a minimum setup
- to be running in under a minute!
Special Note For the Paranoid:
Please feel free to copy an existing database with a table that has at least one searchable varchar or text field.
Demo Installation in Three Easy Steps:
** Step 1: **
- download âjb-ajax-search.zipâ
- Unpack into any new localhost or online ânew-directoryâ
** Step 2: use any editor to modify âdb-results.phpâ
- define(âHOSTâ, âyourHostâ);
- define(âuNAMEâ, âuserNameâ);
- define(âpWORDâ, âpassWordâ);
- define(âdBASEâ, âdataBaseâ);
- define(âdTABLEâ, âtableNameâ);
- define(âdCOL001â, âcolumNameâ); // field must be varchar or text
- define(âdCOL003â, âcolumnNameâ); // field must be NULL or (varchar or text)
** Step3: browse and open â/new-directory/index.phpâ
- finished in less than a minute!
Live Installation in Three Easy Steps:
- copy & paste to your web-page: <?php require âajax-form.phpâ;?>
- copy & paste to your web-page: <div id=âlivesearchâ></div>
- set path to âdb-results.phpâ in âajax-form.phpâ
Suggested Improvements:
- add fields to $sql statement
- format search results
- add pagination to search results
TL;DR - Preliminary Discussion
Recently I have been searching database tables containing foreign characters and tried numerous techniques. Results revealed there is no simple solution. Two effective but slow, clunky methods were syllables and phonemes.
To make nippier searches the phonemes method involved storing an extra column in the table. Both methods involved entering text into a search edit box, clicking enter, parsing the search text into a SQL statement, searching and returning partial or empty no results.
[Ajax to the Rescue](https://en.wikipedia.org/wiki/Ajax_(programming)
Although I have never been a JavaScript fan; this was definitely a big plus for Ajax. Primarily because only a single character needs uploading to a fast server which uses PHPâs MySql used to dynamcally render the browser results.
####W3Schoolâs Ajax Tutorial
was followed and the demos worked. Next task was to update to a server. There were some minor problems but delighted to say it also worked!
Complications arose when trying to interface with CodeIgniter. The biggest problem was the number of files and saving to their correct paths. Simplification was essential if Ajax was to be used on other domains.
Having a working online demo made debugging easier because any failed alternative approaches could easily be rolled back. After exhaustive testing and debugging the project is now online:
Files
- index.php - displays the Live Search and also links to all source code.
- _header.php - required() by index.php and reduces index.php file size.
- _ajax-form.php - required() by index.php. Also contains JavaScript.
- db-results.php - a standalone file that renders database table results also called from the Ajax routine. This file is essential and must display the database table results in order for Ajax to work correctly.
- install.md - this file
- jb-search.zip - zipped contents to be dowloaded and installed into "new-driectory