Jump to content

Recommended Posts

select * from artist where artistName LIKE '%es%'

 

The above query will return all artists that contain "es" in their name.  A whole bunch, basically.

 

How would I modify the search to just show me artists that contain the word es in their name?

 

Lets say there are two bands with weird names like "ES Buzz" and "Through ES".

 

 

Link to comment
https://forums.phpfreaks.com/topic/141092-help-with-like-search/
Share on other sites

No, but it would return what you said above, with things that end with es and start with es.  %es% would return even if in the middle.

 

try this

 

select * from artist where artistName LIKE '%es' OR artistName LIKE 'es%'

 

isn't that the same as LIKE '%es%'?

So you want to have only things with ES (space) and (space) ES returned?

 

Yes.  I want all results that contain the word "es".

 

I tried doing a LIKE '% es %'

 

but if the artistName is "ES Buzz", it won't return it, because there is no space before es.

No, but it would return what you said above, with things that end with es and start with es.  %es% would return even if in the middle.

 

Oh yeah...true.

Again, though.  It would return irrelevant results like strokes, fires, etc.

 

I tried LIKE 'es'

without the %, but it didn't seem to work either.

select * from artist where artistName LIKE '%es ' OR artistName LIKE ' es%'

 

Post your actual code.

 

I'm actually doing it in the phpadmin.  i'm testing the sql.

here's what I'm typing in:

select artistName from artist where artistName LIKE '%es ' OR artistName LIKE ' es%'

 

I added "ES Buzz" and "Through ES" to the artist table.

 

still getting no results.

 

Problem is, just looking at the code, I assume it will give me anything that ends with es or anything that begins with es.

 

What I want is anything that contains exactly the query word or contains exactly the query word plus other words.

 

It is hard to determine that but:

 

select artistName from artist where artistName LIKE 'es ' OR artistName LIKE ' es' 

 

Would/should work for just the ES, the % (wild) card is optional.

 

Problem with that is, lets say they search for a band named Watercolors, with that search it looks for watercolors with a space after it, and watercolors with a space before it.

 

Well, in the database, artistName for the band watercolors is not going to have any spaces, just the word Watercolors, so it actually doesn't return that record.

 

 

I've already showed you how to do it, so I'm not sure what your current question is now.

 

One of us has misunderstood something here.

I'm trying to do a query that searches for a $word and matches records containing exactly that $word or records containing exactly that word plus other words.

 

I have yet to see any post in here that shows me how to do that.  What I'm gathering here, is that a simple query that uses LIKE cannot do that.  Hopefully, I'm wrong about that (I'm pretty much a newbie when it comes to MYSQL), but I'm starting to think that is the case.

How is this not working?

 

select * from artist where artistName LIKE '%es ' OR artistName LIKE ' es%'

 

If someone were to type in "Watercolors", it will not return the band Watercolors because in the artistName field for Watercolors there is no space after Watercolors and there is no space before Watercolors.

 

Basically, that query would fail to return all results of bands where artistname contained only 1 word.

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.