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 Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/ 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. Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430702 Share on other sites More sharing options...
DavidKing0r Posted May 17, 2013 Author Share Posted May 17, 2013 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? Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430715 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 Is there a table named - WHERE 'Short Item Name' ? If does, why did you quote it? Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430730 Share on other sites More sharing options...
DavidKing0r Posted May 17, 2013 Author Share Posted May 17, 2013 The table is called DB Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430736 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 And the columns? Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430738 Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 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. Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430741 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, Link to comment https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.