0

Please I am having some problem with my json file and I am hoping someone can help me. I have searched but can not fully understand the solution i found.

I have checked here json with special characters like é with no luck and some other places too.

Here is my json array script

<?php

$response = array();

require_once __DIR__ . '/db_connect.inc.php';

$result = mysql_query("SELECT id, name, artist_id, year, length, ndisc, keywords, hits, image, review, user_id, tags, genre_id, added, album_file FROM albums ORDER BY id DESC") or die(mysql_error());

if (mysql_num_rows($result) > 0) {

    $response["albums"] = array();

    while ($row = mysql_fetch_array($result)) {

        $album = array();
        $album["id"] = $row["id"];
        $album["name"] = $row["name"];
        $album["artist_id"] = $row["artist_id"];
        $album["year"] = $row["year"];
        $album["length"] = $row["length"];
        $album["ndisc"] = $row["ndisc"];
        $album["keywords"] = $row["keywords"];
        $album["hits"] = $row["hits"];
        $album["image"] = $row["image"];
        $album["review"] = $row["review"];
        $album["user_id"] = $row["user_id"];
        $album["tags"] = $row["tags"];
        $album["genre_id"] = $row["genre_id"];
        $album["added"] = $row["added"];
        $album["album_file"] = $row["album_file"];

        array_push($response["albums"], $album);
    }

    $response["success"] = 1;

    echo json_encode($response);
    } else {
    $response["success"] = 0;
    $response["message"] = "No album found";

    echo json_encode($response);
}

?>

This works fine when there is no special character text in the array. So the problem I am having with this is that it doesn't return anything when special character text such as é, ö, Ø etc is in any of the array field.

So what I want to know is please how can i rewrite this my json script to retrieve those value?

Thank you very much in advance.

Community
  • 1
  • 1
fizzle101
  • 1
  • 1
  • 1
  • Possible duplicate of [json\_encode function: special characters](http://stackoverflow.com/questions/20694317/json-encode-function-special-characters) –  Aug 13 '16 at 19:27
  • 1
    http://stackoverflow.com/a/13478887/1005215 – Nehal J Wani Aug 13 '16 at 19:28
  • How does your JSON look like if it has some `\uxxxx` then those are the special chars. If not then probably your MySQL connection does not return the result in utf-8 and/or the data is already stored incorrectly in the database. – t.niese Aug 13 '16 at 19:29
  • 1
    Please avoid using the `mysql_*` functions. They were deprecated in PHP 5.5, which is so old it doesn't even receive security updates anymore, and removed completely in PHP 7. Instead, use `mysqli_*` functions or PDO. – ChrisGPT was on strike Aug 13 '16 at 19:31

0 Answers0