Comma Seperated Values and LIKE php/mysql Troubles
Posted
by Jay
on Stack Overflow
See other posts from Stack Overflow
or by Jay
Published on 2010-03-23T07:54:39Z
Indexed on
2010/03/23
8:03 UTC
Read the original article
Hit count: 455
The Set up This is more or less a follow up question to something I had previously posted regarding comma separated values (explode,implode). Here's the scenario which has been stomping me the last few days as I'm a noob--sorry for the lengthy post.
I'm passing a variable via the url (index.php?id=variable), I then check the database to find the rows containing that variable using
SELECT * FROM table WHERE column LIKE '%$variable%'
I'm using the wildcards because the results are a comma separated value with the variable appearing multiple times in the database.
So if we were assigning-- say schools to popular tv shows..my database is set up so that the user can assign more than one school to the tv show. IE.
South Park--> fsu, nyu ,mit Archer --> harvard, nyu
Index.php?id=nyu would display Sourth Park & Archer.
The Problem
Because I am using Like '%variable%'
If I have the following: South Park-->uark Archer-->ua
index.php?=ua Instead of just Archer showing, Southpark would also show.
Which makes sense due to the wildcards...but can anyone think of a way to do this achieving the results I want?..Is there any way achieve more precise results using a comma separated value?..I'm completely stomped and will appreciate any help.
© Stack Overflow or respective owner