Jump to content

query using LIKE


CanMan2004

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.