Guest Posted January 27, 2011 Share Posted January 27, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/225799-how-do-i-select-something-from-a-table-that-is-not-exact/ Share on other sites More sharing options...
Guest Posted January 27, 2011 Share Posted January 27, 2011 Solved my own problem. Replaced the spaces with % and it worked fine Let me know if there's a better way though, please. Quote Link to comment https://forums.phpfreaks.com/topic/225799-how-do-i-select-something-from-a-table-that-is-not-exact/#findComment-1165846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.