Jump to content

Recommended Posts

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

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 by DavidKing0r
Link to comment
https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430715
Share on other sites

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 by jazzman1
Link to comment
https://forums.phpfreaks.com/topic/278104-mysql-queries/#findComment-1430741
Share on other sites

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

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.