0

Form my form i have a range of date like this :

05/16/2016,05/17/2016,05/18/2016

Inside my table i have :

-----------------------------------
ID   |   Key   |   Value   
-----------------------------------
10   |   mydt  |   05/14/2016,05/15/2016,05/16/2016,05/17/2016, 05/18/2016,05/19/2016,05/20/2016

I have to search if my $_POST['date'] is inside value, following will not working :

SELECT * FROM my_table WHERE key = mydt AND value LIKE '%05/16/2016,05/17/2016,05/18/2016%'

SELECT * FROM my_table WHERE key = mydt AND value IN('05/16/2016','05/17/2016','05/18/2016')

How to handle this please ? thanks for your help

  • 3
    If `key` is the actual column name, look up https://dev.mysql.com/doc/refman/5.5/en/keywords.html and checking for errors would have signaled it. It requires special treatment as in using ticks `\`` around it. Oh, and don't bother making it plural, as `keys` is another MySQL reserved word. – Funk Forty Niner May 04 '16 at 15:34
  • CSV, is not a good format for a DB. You should normalize your table and have one row per record. You might have to split your table into two depending on what you are doing. Dates also should be stored as the date datatype, not varchar. – chris85 May 04 '16 at 15:38

1 Answers1

1

May be you have forgotten or or and command

SELECT * FROM my_table WHERE key = mydt AND value LIKE '%05/16/2016% or LIKE '%05/17/2016%' or LIKE '%05/18/2016%'

Try it....

cchapman
  • 3,269
  • 10
  • 50
  • 68
Googlian
  • 6,077
  • 3
  • 38
  • 44