php - Select Query is not working as it should work - MYSQL -


i have data in database represents name, state , types of cases attorney does:

name: new attar

states: a:2:{i:0;s:13:"massachusetts";i:1;s:13:"new hampshire";}

cases types a:13:{i:0;s:1:"5";i:1;s:1:"7";i:2;s:1:"8";i:3;s:1:"9";i:4;s:2:"10";i:5;s:2:"11";i:6;s:2:"13";i:7;s:2:"14";i:8;s:2:"15";i:9;s:2:"16";i:10;s:2:"17";i:11;s:2:"18";i:12;s:2:"19";}

name: kevin regan

states: a:1:{i:0;s:13:"massachusetts";}

cases types a:1:{i:0;s:2:"14";}

name: matthew gendreau

states: a:2:{i:0;s:13:"massachusetts";i:1;s:13:"new hampshire";}

cases types a:16:{i:0;s:15:"multiselect-all";i:1;s:1:"5";i:2;s:1:"2";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";i:6;s:2:"10";i:7;s:2:"11";i:8;s:1:"1";i:9;s:2:"13";i:10;s:2:"14";i:11;s:2:"15";i:12;s:2:"16";i:13;s:2:"17";i:14;s:2:"18";i:15;s:2:"19";}

the query using is:

select     *     `web_attorney`     (         `at_status` = '1'         or (             `at_status` = '2'             , '2015-05-15' not between `at_inactive_date_from`             , `at_inactive_date_to`             , `at_inactive_date_from` != ''             , `at_inactive_date_to` != ''         )     ) , (     `at_juris_states` '%massachusetts%' ) , (     `at_availability` '%friday%' ) , (`at_cases` '%2%') order     `at_has_mt` asc limit 5 

problem:

i want fetch records cases type 2.

since using on php serialize array query works issue comes cases types not 2 , 2. both coming query.

it picks attorneys have not case type 2. new attar not have case type 2 in double qoutes "2" in query comes when don't.

update

here fiddle example:

http://sqlfiddle.com/#!9/e4c3c/1

a normalized approach might this:

attorneys attorney_id*, name           2 , kevin regan           3 , matthew  gendreau   attorney_state attorney_id*, state*           2 , massachusetts           3 , massachusetts           3 , new hampshire  attorney_casetype attorney_id,casetype           2,      14           3,       2            3,       7           3,       8           3,       9           3,      10           3,      11           3,       1           3,      13           3,      14           3,      15           3,      16           3,      17           3,      18           3,      19          

* = (component of) primary key


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -