I'm trying to receive the data from JSON with PHP and use it in my SELECT query. I have searched everywhere and every solution didn't worked for me.
My Returned JSON data:
"{processos:[{"processo":"203"},{"processo":"1430"}]}"
My PHP:
$ar2 = json_decode($processo2, true);
$where2 = array();
foreach($ar2['processo'] as $key=>$val){
$where2[] = $val;
}
$where2 = implode(',', $where2);
$pegaSonda = $pdo->prepare("SELECT * FROM sonda WHERE n_processo IN ($where2)");
$pegaSonda->execute();
What's wrong with my code?
EDIT
The code from @wadersgroup worked correctly, but when i change to my variable it stops. This is the way i'm encoding it:
$jsonData = array();
$jsonData[] = array("processo" => $automovel->n_processo);
$data['processo2'] .= '{"processos":'.json_encode($jsonData).'}';
$data['processo2'] is sending to my AJAX to populate the input and then it receive data back with:
$processo2 = strip_tags(stripslashes($_POST['n_processo2']));
$ar2 = json_decode($processo2, true);maybe a typo to$ar2 = json_decode($processos, true);ar2not$processos, so try$ar2.processos['processo']