0

I have created a forum where you can ask questions to musicians. I have a form where you can select multiple checkboxes to what kind of musicians you want to talk to.

With the POST data I did the following:

$result = implode(",",$_POST['sub']);

And insert it into the database table which look like this:

-------------------------------------------
| id  | topicname | genre |    Subgenre   |
-------------------------------------------
|  1  |   music   | Metal | Heavy, Thrash |
-------------------------------------------

So what I want is only musicians that have signed up on the site with either heavy or Thrash can interact with this forum topic. I know how to check it normally if there was only 1 variable in the table but now there is two and I have no clue how to solve this problem.

3
  • use the OR operator. SELECT * FROM Table WHERE col1 = 'value' OR col2 = 'value2' Commented Jun 3, 2016 at 9:57
  • But i dont think i can use this because another topic could have 3 or 4 different subgenre checked when they are submitted to the database. Commented Jun 3, 2016 at 10:00
  • Consider your table structure. It might be worth thinking about how you are storing the information in the database such that data duplication and assignment becomes simpler. Commented Jun 3, 2016 at 10:04

1 Answer 1

0

why don't you use 'like' function in mysql. It retrive the record match with the string found in the table column. Just like following code

SELECT * FROM table_name WHERE `genre` LIKE '%metal%' OR `Subgenre` LIKE '%metal%'

Hope it solve your issue... Good Luck..

Sign up to request clarification or add additional context in comments.

5 Comments

How would using LIKE solve anything? The values in the table are exact, and this isnt a search type request (or, rather, shouldn't be).
SELECT * FROM TableName WHERE Column_name IN (column1, column2, column3, column4)
If you merge more than one record in a single row with implode of comma then how IN function find the perfect match to serve the data. For Instance if I have a data like "Heavy, Thrash" and another record have ("Thrash, Heavy") from this case IN function wont retrieve the record so I use LIKE function to match the record. Because I too face same problem for one of my application and It working fine buy using LIKE method. Hope you understand my scenario...
Like actually worked! I could use it into mysql_row to see if i got 1 that reminded og the variable! Thanks alot! Have a wonderfulll weekend

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.