I have a database which holds a series of numbers and letters in a field called 'data', I then have a search form which does query on this data in the database. Some sample data that is being held looks like
The query I currently use is
$sql = "SELECT * FROM data WHERE `code` LIKE '%".$code."%' LIMIT 20";
for example, if
is searched, then record
is searched, it would also return
I can also search part of a code, as long as its the start of the code. As you will see by my query, I limit 20 records, but at the moment, I don't have enough records stored in the database to bring back 20 and no more and no less.
What I want to do is to be able to do is to do a query and retrieve 15 records each time, no more, no less. As I dont have the amount of records to ensure I always get 15 returned, I want to be able to display (below the most matched results) the closest records found to the one which was just searched, which would then make a total of no more than 20.
Can this be done with ease in php or could someone please help me out as ive been trying to figure it out all weekend and am having no job.
Thank you for any help in advance