Jump to content


Photo

query using LIKE


  • Please log in to reply
2 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 18 September 2006 - 11:39 PM

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

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

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 September 2006 - 11:51 PM

I want to be able to display (below the most matched results) the closest records found to the one which was just searched,


Define closest
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 19 September 2006 - 12:56 PM

How do you define closest?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users