php echo json in foreach loop
- by Vidya Sagar
i have product ids like this 1,2,3 in $product_ids var
$product_ids = explode(',', $product_ids);
$product_ids = array_filter($product_ids);
foreach ($product_ids as $key => $product_id) {
$sth = $this->db->prepare("SELECT * FROM products Where id =:id ");
$sth->execute(array( ':id' => $product_id ));
$final_data = $sth->fetchAll();
echo json_encode($final_data);
}
how can i format json whit this code in for loop echo json not working is there any other way plz help