Grid Login Demo

9th January 2012 · Last updated: 5th October 2016


Chris commented on my Flat File Database Demo 5:

I'm wondering if it's possible to modify the code to search for 4 keywords instead of 2 and based on a grid layout similar to below:


So for example you'd search for 3B, 2H, 5J, 1C and it would return the corresponding results: 5, J, Q, M.

He needed this for work, where he had to look up four letter/number combinations on a paper grid and enter the results to log in. I envisaged you could do this using a flat file database to store the grid, accessing it using PHP arrays. This demo is the result.


The demo uses a single input to enter the four keywords needed. These are then stripped out into four separate strings. Then I realised it was just a matter of converting the letters A-J above the grid into numbers, so you could reference the columns in the grid. I used PHP's ord function to do that. I could then access the grid using an array format like this:


Note how PHP cleverly allows you to include variables within array brackets. Normally you'd use numbers there, eg: $col[1][2];. $col is the name of the array I used. The other two variables are split from the input string to give you the column and row respectively.

Take a look at the code via the demo to see how it works. I've also added error traps incase the input isn't in the right format, or letters and numbers out of the range of the grid are typed in.

Comments (1)

  1. Web Design Company:

    Intriguing but what's the end product? I mean with normal search being able to exactly pinpoint what you are looking for, how do grid coordinates improve upon the current system? Unless of course you are planning on playing Battleship.

    Posted on 11th April 2012 at 2:25 pm