1
Array
(
    [0] => Array
        (
            [acctcode] => 631
            [description] => Blood Transfussion Set, Blood Transfusion Set- ADULT
            [pchrgqty] => 1.00
            [pchrgup] => 17.00
            [pcchrgamt] => 17.00
            [patlast] => GUADA�A
            [patfirst] => FRITZIE ELINE
            [patmiddle] => DAYTEC
            [patsuffix] => 
        )

)

The above array in php is result of print_r($result); now this array will be json_encoded as below:

echo json_encode($result, JSON_UNESCAPED_UNICODE);

I am encoding this because it is for ajax request. Now in echo part it is not returning anything. I dont know why this is happening but my guess is because of “Ñ” which is in the [patlast] => GUADA�A and is shown as . I am getting this result set in a select of MSSQL DATABASE.

How to handle this result set in MSSQL and be able to return the correct data.

Mehul Kuriya
  • 608
  • 5
  • 18
Martin
  • 365
  • 4
  • 7
  • 22

1 Answers1

1

I have found the best solution for my project in here

Using below code:

// Create an empty array for the encoded resultset

$rows = array();

// Loop over the db resultset and put encoded values into $rows

while($row = mysql_fetch_assoc($result)) {
  $rows[] = array_map('utf8_encode', $row);
}

// Output $rows

echo json_encode($rows);

The answer was given my user Kemo

Martin
  • 365
  • 4
  • 7
  • 22