Jump to content

How do I select something from a table that is not exact?


Guest

Recommended Posts

On my site, there are a number of articles each of which is stored as a row in a MySQL table. Each row has a tags field, and each tag in the tags field is separated by a comma and a space, like this: "Tag 1, Tag 2, Tag 3"

 

The problem occurs when I try to get the articles from the table by a specific tag because I am parsing out special characters in the URL.

 

For example, I have several rows that contain "Silent Hill: Downpour" in the tags field. When I click on the tag on my site, it takes me to the following URL:

 

mysite/search/tag/Silent_Hill__Downpour

 

As you can see, the spaces and special characters are replaced by underscores so that it is URL friendly. On that page, I replace the underscores with spaces. So I am trying to select the articles form the database like this:

 

SELECT * FROM `news` WHERE tags LIKE '%Silent Hill  Downpour%'

 

instead of this:

 

SELECT * FROM `news` WHERE tags LIKE '%Silent Hill: Downpour%'

 

The first query returns zero results, but the second returns all the articles that have that tag. How can I get it to select the rows that are similar to the tag with or without a colon?

Link to comment
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.