php - selecting the rows in mysql with arrays -


in db, have table, timetable 1 field subject. hold value this. example. 1,2,3,4

now, need compare field array named

$mysubs=array('1','3','5'); 

i have tried this.

select * timetable  subject in (".implode(',',$mysubs)."); 

but if have 1 value in subject field working. if holding 1,2,3 not working. possible match using 'like'. plz me

try thing if subject field value comma separated.

$mysubs = array('1','3','5'); $wheresubclause = ''; for($i=0; $i < count($mysubs); $i++){    $wheresubclause .= 'find_in_set($i,subject) or '; } // remove last or $wheresubclasue = substr($wheresubclause,0,-3);  // query select * timetable  $wheresubclause; 

but if not comma separated this:

$values = implode("','",$mysubs); "select * timetable subject in('".$values."');" 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -