Query to check if value is in a json_encode table column??

Discussion in 'MySQL' started by 123GoToAndPlay, Oct 12, 2010.

  1. #1
    Hello,

    Is there a way to check if a value is within a json_encoded table column???
    in combo with php i have something like

    
    function totPerWorkshop($id){
    
    $q = "SELECT * FROM tblWorkshop WHERE workshops = $id"
    
    
    }
    
    Code (markup):
    where workshops is a column which stores json_endoced values (for example: ["3","10"])

    How to do this with mysql???

    regards
     
    123GoToAndPlay, Oct 12, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You could probably use a regular expression to check. However, this is normally handled on the application level. You should be able to simply use json_decode. If it return NULL it is not JSON, otherwise it is.
     
    jestep, Oct 12, 2010 IP