-2
請幫助,我試了一切。我從我的數據庫獲取的數據是utf8_bin,並在php中顯示,但是當我把字符如ć,č,ž,Json顯示數字時,我已經嘗試過mysql_query(「SET NAMES'utf8'」); mysql_query(「SET CHARACTER_SET'utf8'」);但沒有。我的Json代碼是:Json編碼顯示數字而不是字母
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
$sviArray = array();
$responseZagreb=array();
// include db connect class
require_once('DB_connect.php');
// connecting to db
$db = new DB_connect();
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER_SET 'utf8'");
// get all products from products table
$result = mysql_query("SELECT *FROM Istra") or die(mysql_error());
$resultZagreb = mysql_query("SELECT *FROM Zagreb") or die(mysql_error());
$place=array();
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["Istra"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["id"] = $row["ID"];
$product["datum"] = $row["DATUM"];
$product["grad"] = $row["GRAD"];
$product["place"] = $row["PLACE"];
$product["adresa"] = $row["ADRESA"];
$product["Dogadaj"]=$row["DOGADAJ"];
$product["Cijena"]=$row["CIJENA"];
$product["Slika"]=$row["SLIKA"];
$product["Tip"]=$row["TIP"];
$place=$row['PLACE'];
$result0 = mysql_query("SELECT SUM(ocjena) AS value_sum FROM Ocjena where place='$place'");
$cijena=mysql_query("SELECT SUM(cijena) AS values_cijena FROM Ocjena where place='$place'");
$cijenacount=mysql_query("SELECT COUNT(cijena) AS cijena_count FROM Ocjena where place='$place'");
$result1=mysql_query("SELECT COUNT(ocjena) AS value_sum1 FROM Ocjena where place='$place'");
$row0 = mysql_fetch_assoc($result0);
$row1 = mysql_fetch_assoc($result1);
$row2=mysql_fetch_assoc($cijena);
$row3=mysql_fetch_assoc($cijenacount);
$sum0 = $row0['value_sum'];
$sum1 = $row1['value_sum1'];
$sum2=$row2['values_cijena'];
$sum3=$row3['cijena_count'];
if($sum1!=0){
$rez=$sum0/$sum1;
}
else $rez=0;
$product["Ocjena"]=$rez;
if($sum2!=0){
$rezCijena=$sum2/$sum3;
}
else $rezCijena=0;
$product["cijena"]=$rezCijena;
// push single product into final response array
array_push($response["Istra"], $product);
}
// success
$response["success"] = 1;
$responseZagreb["Zagreb"] = array();
while ($row1 = mysql_fetch_array($resultZagreb))
{
// temp user array
$productZagreb = array();
$productZagreb["id"] = $row1["ID"];
$productZagreb["datum"] = $row1["DATUM"];
$productZagreb["grad"] = $row1["GRAD"];
$productZagreb["place"] = $row1["PLACE"];
$productZagreb["adresa"] = $row1["ADRESA"];
$productZagreb["Dogadaj"]=$row1["DOGADAJ"];
$productZagreb["Cijena"]=$row1["CIJENA"];
$productZagreb["Slika"]=$row1["SLIKA"];
$productZagreb["Tip"]=$row["TIP"];
$place=$row['PLACE'];
$result0 = mysql_query("SELECT SUM(ocjena) AS value_sum FROM Ocjena where place='$place'");
$result1=mysql_query("SELECT COUNT(ocjena) AS value_sum1 FROM Ocjena where place='$place'");
$row0 = mysql_fetch_assoc($result0);
$row1 = mysql_fetch_assoc($result1);
$sum0 = $row0['value_sum'];
$sum1 = $row1['value_sum1'];
if($sum1!=0){
$rez=$sum0/$sum1;
}
$productZagreb["Ocjena"]=$rez;
// push single product into final response array
array_push($responseZagreb["Zagreb"], $productZagreb);
}
// looping through all results
// products node
$sviArray=array_merge($responseZagreb,$response);
// echoing JSON response
echo stripcslashes(json_encode ($sviArray));
}
else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
}
?>
根本不工作。沒有數據顯示 –