Jump to content

javascript generated by php character problem


anatak

Recommended Posts

Hello,

I am trying to make a dropdown of states (ken) and cities (city)
the dropdown has to display the names of the states and cities in the user selected language if available and if not available in the default language.

the problem I have is that when I try to display the japanese names of the cities it does not display the japanese characters but some gibberish (I guess some representation of the characters)
This does not happen with the japanese names of the states.

I attach a zip file with 4 files in the folder phppost
city.sql is the mysql export for the city table
ken.sql is the mysql export for the ken table
function.txt is the php file that has the function that will display the dropdown
form.txt is the php file that holds the form where the dropdown will be displayed.

the function takes 4 arguments
$city01, $dbread, $time, $default_language
$city01 = null; will work
$dbread = ADOdb connection with read permissions
$time = 1; will work this is the time to cache the query
$default_language = 1; will work

here is the function
i have changed script in the tags to DELETED

[code]
<?php
function new_location_edit($city01, &$dbread, $time, $default_language)
{
$userlang_ken="KenNameLan_".$_SESSION['userlanguage'];
$defaultlang_ken="KenNameLan_".$default_language;
$userlang_city="CityNameLan_".$_SESSION['userlanguage'];;
$defaultlang_city="CityNameLan_".$default_language;;
// echo "userlang: ".$userlang_ken;
$TableName1 = 'ken';
$TableName2 = 'city';
//$Query is the query that select the list of prefecture ordered by name
$QuerySelectKen = "SELECT $TableName1.*
FROM $TableName1
WHERE KenId <> 1
order by KenNameLan_1 ASC;";
//echo $QuerySelectKen . '<BR>';
$Result1= $dbread->CacheGetAll($time,$QuerySelectKen);
foreach($Result1 AS $Row1){
if($Row1[$userlang_ken]==null){
$kens[($Row1['KenId'])]['name'] = $Row1[$defaultlang_ken];
}else{
$kens[($Row1['KenId'])]['name'] = $Row1[$userlang_ken];
}

// $kens[($Row1['KenId'])]['name'] = $Row1['KenNameLan_1'];
$QuerySelectCity = "SELECT $TableName2.*
FROM $TableName2
WHERE $TableName2.KenId = $Row1[KenId]
OR $TableName2.KenId = '0'
ORDER BY CityNameLan_1 ASC;";
// echo $QuerySelectCity . '<BR>';
$Result2 = $dbread->CacheGetAll($time,$QuerySelectCity);
foreach($Result2 AS $Row2){
if($Row2[$userlang_city]==null){
//echo "<br />".$Row2['CityId']."null";
$kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$defaultlang_city];
}else{
echo  "<br />".$Row2['CityId'].": ".$Row2[$userlang_city]." ".$Row2[$defaultlang_city];
$kens[($Row1['KenId'])]['city'][($Row2['CityId'])] = $Row2[$userlang_city];
}
}
}
//get the ken and city for this user
if($city01!=null){
$QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.KenNameLan_1
FROM $TableName2
LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId
WHERE $TableName2.CityId = $city01;";
}else{
//echo "city = null";
$QuerySelectKenCity = "SELECT $TableName2.*, $TableName1.*
FROM $TableName2
LEFT JOIN {$TableName1} ON {$TableName2}.KenId = {$TableName1}.KenId
WHERE $TableName2.CityId = 1;";

}
echo $QuerySelectKenCity;
$Row3 = $dbread->CacheGetRow($time,$QuerySelectKenCity);
//echo "KEN: ".$Row3['KenNameLan_1'].$Row3['KenId'];
//echo "CITY: ".$Row3['CityNameLan_1'].$Row3['CityId'];

print <<<LLL
<DELETED language="Javascript" type="text/javascript">
<!--
function showKens(){
var kenList = document.form1.ken;
var cityList = document.form1.city;
var kenId = kenList.options[kenList.selectedIndex].value;
var cityName = '';

cityList.options.length = 0;

i = 0;
for (y in ken_array[kenId].city){
cityName = ken_array[kenId].city[y];
cityList.options[i] = new Option(cityName, y);
i++;
}
}
var ken_array = new Array();
LLL;
foreach ($kens as $kenId=>$kenDetails){
$kenName = $kenDetails['name'];
print <<<LLL

ken_array[$kenId] = new Array();
ken_array[$kenId].name = '$kenName';
ken_array[$kenId].city = new Array();
LLL;
foreach ($kenDetails['city'] as $cityId=>$city){
print <<<LLL

ken_array[$kenId].city[$cityId] = '$city'
LLL;
}
}
print <<<LLL

document.write('<select name="ken" onchange="showKens()">');
LLL;
if($Row3[$userlang_ken]==null){
print <<<LLL
document.write('<option value="$Row3[KenId]">$Row3[$defaultlang_ken]</option>');
LLL;
}else{
print <<<LLL
document.write('<option value="$Row3[KenId]">$Row3[$userlang_ken]</option>');
LLL;
}
print <<<LLL
for (var i in ken_array){
document.write('<option value="'+i+'">'+ken_array[i].name+'</option>');
}
document.write('</select>');
document.write('<input name="kenname" type="hidden" value="$Row3[KenNameLan_1]">');
LLL;
if($Row3[$userlang_city]==null){
print <<<LLL
document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$defaultlang_city]<option></select>');
LLL;
}else{
print <<<LLL
document.write('<select name="city"><option value="$Row3[CityId]">$Row3[$userlang_city]<option></select>');
LLL;
}
print <<<LLL
document.write('<input type="hidden" name="cityname" value="$Row3[CityNameLan_1]">');
-->
</DELETED>
LLL;
}
?>
[/code]

here is the form
changed the script into DELETED
[code]
<DELETED language="Javascript" type="text/javascript">
<!--
document.write('<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?p=p10&select=05'?>">');
-->
</DELETED>
<?php
new_location_edit(null, $dbread, $short, $default_language);
?>
[/code]

All help is greatly appreciated
Maybe I should post this in the javascript forum but I ll try here.

anatak



[attachment deleted by admin]
The behavior of this problem is that it looks like the Japaneses text is displayed as non japanese (maybe western iso-8859-1)
What I don't understand is that is that the script displays the Japanese text correctly in the first dropdown but not in the second dropdown.
Does anybody know if Javascript is unable to display Japanese (2byte) text ?
I am thinking this because the second dropdown is generated by the showKens() javascript function and the first dropdown is not generated using javascript.

thanks
anatak

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.