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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.