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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -