Mysql where id is in array [duplicate]

$string=”1,2,3,4,5″; $array=array_map(‘intval’, explode(‘,’, $string)); $array = implode(“‘,'”,$array); $query=mysqli_query($conn, “SELECT name FROM users WHERE id IN (‘”.$array.”‘)”); NB: the syntax is: SELECT * FROM table WHERE column IN(‘value1′,’value2′,’value3’)

PHP explode the string, but treat words in quotes as a single word

This would have been much easier with str_getcsv(). $test=”Lorem ipsum “dolor sit amet” consectetur “adipiscing elit” dolor”; var_dump(str_getcsv($test, ‘ ‘)); Gives you array(6) { [0]=> string(5) “Lorem” [1]=> string(5) “ipsum” [2]=> string(14) “dolor sit amet” [3]=> string(11) “consectetur” [4]=> string(15) “adipiscing elit” [5]=> string(5) “dolor” }

PHP: Split string into array, like explode with no delimiter

$array = str_split(“0123456789bcdfghjkmnpqrstvwxyz”); str_split takes an optional 2nd param, the chunk length (default 1), so you can do things like: $array = str_split(“aabbccdd”, 2); // $array[0] = aa // $array[1] = bb // $array[2] = cc etc … You can also get at parts of your string by treating it as an array: $string = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)