DavidKing0r Posted May 17, 2013 Share Posted May 17, 2013 Hi. I have a rather large database and i require to search 'Short Item Name' for keywords (2/3 words). Not all 3 words need to be in each result. Also I'd like to know how I would search 'Number' for a partial match so if one of the records 'Number' was 098214984212 and I entered 4984212 (last 7) into a form how would i retrieve that record? Thanks really appreciate if anyone helps me out. dave Quote Link to comment Share on other sites More sharing options...
jcbones Posted May 17, 2013 Share Posted May 17, 2013 LIKE using the wildcard (%) is what you are looking for. Quote Link to comment Share on other sites More sharing options...
DavidKing0r Posted May 17, 2013 Author Share Posted May 17, 2013 (edited) Thanks i gathered that having a bit of trouble now though. Heres what I have in my Table for example. No | Short Name | Long Name 21421414 | Treble blah tree | Treble tree with a blah ring 52352352 | wqe weqwe | wqe weqwe weqrqwr rwqr qw Im now trying to search the short name with $query = "SELECT * FROM DB WHERE 'Short Item Name' LIKE '%$searchTerm1%' AND '%$searchTerm2%'"; However it doesnt appear to work any ideas? Edited May 17, 2013 by DavidKing0r Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 (edited) Is there a table named - WHERE 'Short Item Name' ? If does, why did you quote it? Edited May 17, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
DavidKing0r Posted May 17, 2013 Author Share Posted May 17, 2013 The table is called DB Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 And the columns? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 (edited) The right syntax should be something like: SELECT * FROM tbl_name WHERE column_name_1 LIKE '%a%' AND column_name_2 LIKE '%b'; Also, don't quote the tables and columns it's a wrong sql syntax. Sorry, I am in a hurry. Edited May 17, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
dalecosp Posted May 17, 2013 Share Posted May 17, 2013 To elaborate a tad further, you often see this: select `something` from `someplace` where `some_condition` = 1234;Those are "backticks", and people that use them use them in order to make sure that their SQL server, (MySQL in this case, and especially) doesn't choke on any terms. For example, you can use a reserved word as a column name, but only if you enclose it in backticks. I tend NOT to use them, and to (properly, I believe) refrain from using SQL Reserved Words as column names. HTH, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.