Flat File Database Demo 4
Now with added search function!
16th January 2009 · Last updated: 5th October 2016
Doug F emailed me to ask if it was possible to add a search function to my flat-file database script. It is! In fact I had already written a basic search function before but for different code. So I added new code from scratch that would work with the second flat-file demo here.
You can now search for a word in the database and it will show each row that contains it. I even added a highlight to the words that match your search!
A simple form is used to enter the search word on the first page. This is passed to a second page that looks for the word in each field of the database. If the word is found then the script will also output the full row from the database into a table. If the word isn't found then a simple error message is shown.
Update 21st January 2009: Improved the code so part words can be searched for. It will also pick up words of any case (upper or lower, or mixed).
Update 20th April 2010: It now displays the number of searches found. Thanks to Frank Höfken for the inspiration!