Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

query using LIKE

Recommended Posts

Hi

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

DDE21 7YHGB
ACN64 4RFVB
NJ99 4CVBPO
VH5 4RFJ

The query I currently use is

[code]$sql = "SELECT * FROM data WHERE `code` LIKE '%".$code."%' LIMIT 20";[/code]

for example, if

DDE21

is searched, then record

DDE21 7YHGB

is returned

and if

7YHGB

is searched, it would also return

DDE21 7YHGB

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

Ed

Share this post


Link to post
Share on other sites
[quote]I want to be able to display (below the most matched results) the closest records found to the one which was just searched,[/quote]

Define [b]closest[/b]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.