php echo json in foreach loop
        Posted  
        
            by 
                Vidya Sagar
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Vidya Sagar
        
        
        
        Published on 2012-11-12T10:58:31Z
        Indexed on 
            2012/11/12
            10:59 UTC
        
        
        Read the original article
        Hit count: 329
        
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
© Stack Overflow or respective owner