时间:2021-07-01 10:21:17 帮助过:24人阅读
先看看都是什么样的数据
??格式是怎?的?
正常json_decode後????可以解???了。
数据格式是 [{"answer":"123"},{"answer":"222"},{"answer":"231"}]
数据格式是 [{"answer":"123"},{"answer":"222"},{"answer":"231"}]
如果传入数据的键名都是一样的,则
$s = '[{"answer":"123"},{"answer":"222"},{"answer":"231"}]';$d = json_decode($s, true);$t = join(',', array_map('current', $d));$k = key(current($d));$sql = "select * from tbl_name where $k in ($t)";select * from tbl_name where answer in (123,222,231)
$data = '[{"answer":"123"},{"answer":"222"},{"answer":"231"}]';$data = json_decode($data, true);$answers = array();foreach($data as $val){ array_push($answers, $val['answer']);}$sqlstr = "select * from table where answer in('".implode("','", $answers)."')";#mysql_query($sqlstr) or die(mysql_error());echo $sqlstr; // select * from table where answer in('123','222','231')