0

I have a MYSQL result array which needs to be json decoded.

Below is my code:

foreach ($result as $row) {
    $list[] = $row;
}
$response['data']    = $list;
echo json_encode($response);exit;

It seems some simple silly thing is missing. The array in the $result is an array from mysql select query.

When i check the output it is showing blank where as i can see the array properly printed out. Do i have to define an array by looping through all values?

Below is my array structure:

Array ( [placement_id] => 1130 [name] => Verizon [os_id] => 2494 [profile_id] => 1130 )

Solution to my problem:

col1 was having special characters, so removed using below expression inside my foreach loop:

$row['col1'] = preg_replace('/[\x00-\x1F\x7F-\xFF]/', '', $row['col1']); 
Wolverine
  • 455
  • 3
  • 8
  • 26

0 Answers0