Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problems with danish char in database

Reply
Thread Tools

Problems with danish char in database

 
 
Tine Mller
Guest
Posts: n/a
 
      04-02-2008
Can someone help me what code to change so it's functioning with danish char
which is in the database?

<?php
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers_library_copy");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers_library_copy table
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos(
radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) -
radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS
distance FROM markers_library_copy HAVING distance < '%s' ORDER BY distance
LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);

if (!$result) {
die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}

echo $dom->saveXML();

?>



--
M.v.h.
Tine Mller

homepage: http://tine_muller.homepage.dk/


 
Reply With Quote
 
 
 
 
Andreas Prilop
Guest
Posts: n/a
 
      04-02-2008
Tine M?ller wrote:

> X-Newsreader: Microsoft Outlook Express 6.00.2900.3138


Start with your newsreader^W Outlook Express.
You need to choose

Tools → Options → Send
Mail Sending Format → Plain Text Settings → Message format MIME
News Sending Format → Plain Text Settings → Message format MIME
Encode text using: None

in order to send special, non-ASCII characters.
 
Reply With Quote
 
 
 
 
Tine Müller
Guest
Posts: n/a
 
      04-02-2008
"Andreas Prilop" wrote
> Start with your newsreader^W Outlook Express.
> You need to choose
>
> Tools → Options → Send
> Mail Sending Format → Plain Text Settings → Message format MIME
> News Sending Format → Plain Text Settings → Message format MIME
> Encode text using: None
>
> in order to send special, non-ASCII characters.


Is it done right now?


 
Reply With Quote
 
Tine Müller
Guest
Posts: n/a
 
      04-02-2008
My testsite can be seen here
http://www.tinemuller.dk/googlemap/t...search_map.htm
and the tutorial I have been following here
http://code.google.com/support/bin/a...69&ctx=sibling.

I got it working using a database without danish char and it's here
http://www.tinemuller.dk/googlemap/t...search_map.htm

M.v.h.
Tine Müller


 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      04-02-2008
On 2 Apr, 14:05, "Tine Mller" <(E-Mail Removed)> wrote:
> Can someone help me what code to change so it's functioning with danish char
> which is in the database?


I had a good answer, but the accursed Google Groups interface ate it
8-(

Lose the <meta> in your page. You're sending a HTTP-Header too (better
idea anyway) and that will take precedence. As the page is claiming
to be UTF-8, then you'd better send UTF-8 / Unicode characters in it,
not ISO-8859 characters. If your DB is working in ISO-8859 already,
then you might find it easier to change the page generation code to
send the right HTTP header.

Read up (Wikipedia is good) on Unicode, ISO-8859 and the distinctions
between "character sets" (lists of squiggles that humans use) and
"character encoding" (sequences of bytes that computers use to refer
to these squiggles).

You _must_ use a character set that includes the squiggle you need.
Danish is easy (commonplace ISO-8859-1 suffices), Czech or Polish is
harder. In general these days, go straight to Unicode. This works for
all languages at once, ISO-8859 requires you to swap between
ISO-8859-1 and ISO-8859-4 depending on which side of the Baltic you
are.

You then need an encoding that works for the character set you use and
is configured so that your DB content matches your page (or gets
translated) and your page's header matches your page's content. Use
UTF-8 for Unicode, use the relevant ISO-8859-* for ISO-8859 (and you
would have to swap between sides of the Baltic).


Alternatively (a very bad idea, I only mention it to save a follow-up
pinhead doing so), use plain old ASCII as an encoding and HTML numeric
character entities or HTML entity references. You will find that
numeric character entities are no easier to generate than UTF-8 (if
your DB contains ISO-8859) and that entity references are a big chunk
of tedious look-up code to create (maybe a PHP library exists for
this). This approach is tedious, but it does work in cases where you
can't fix the web server's HTTP-Headers to indicate a correct or
useful encoding.
 
Reply With Quote
 
Andreas Prilop
Guest
Posts: n/a
 
      04-04-2008
Tine Müller wrote:

> MIME-Version: 1.0
> Content-Type: text/plain;
> charset="UTF-8";
>
> Is it done right now?


Very well - yes.
 
Reply With Quote
 
Tine Mller
Guest
Posts: n/a
 
      04-05-2008
"Andy Dingley" wrote
I had a good answer, but the accursed Google Groups interface ate it
8-(

I'm not sure what you mean here?

I have trouble understand your technic explanation and maybe it's because my
language is danish and that this is NOT easy to understand, sorry.

I have made some inprovements on another testmap
http://www.tinemuller.dk/googlemap/t...search_map.htm
but there is still problems. If you look in the code you can see that I have
tried a lot of doctype and charset. In my table on my host is says
"utf8_danish_ci" but try search for "Smakkegrdsvej 112" and "1" and you
will see the problem and then try with "3" and you will see an error message
in Firebug.

I have ask'ed Pamelas who made the tutorial here
http://code.google.com/support/bin/a...69&ctx=sibling
to show us the code to use when you use foreign language as for instance
danish but haven't heard anything from here yet.

If you would help me some more I could send you my files to you privately
and maybe you could test on your host also using "utf8_danish_ci" to see if
YOU can get it to work, please?

library_phpsqlsearch_genxml.php

<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>-->

<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="da" lang="da">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Tine - Google Maps AJAX + MySQL/PHP Example</title>
<script
src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAmYYoLeRyazVGDeFwMH_5 chRBa9hFh1JQE70w75ZW5bLNFA531BSqFdAlOuedN5j5p0Nzme k2tUeZkA"
type="text/javascript"></script>
<script type="text/javascript">

//<![CDATA[
var map;
var geocoder;

var iconBlue=new GIcon();
iconBlue.image='http://labs.google.com/ridefinder/images/mm_20_blue.png';
iconBlue.shadow='http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconBlue.iconSize=new GSize(12, 20);
iconBlue.shadowSize=new GSize(22, 20);
iconBlue.iconAnchor=new GPoint(6, 20);
iconBlue.infoWindowAnchor=new GPoint(5, 1);

var iconRed=new GIcon();
iconRed.image='http://labs.google.com/ridefinder/images/mm_20_red.png';
iconRed.shadow='http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconRed.iconSize=new GSize(12, 20);
iconRed.shadowSize=new GSize(22, 20);
iconRed.iconAnchor=new GPoint(6, 20);
iconRed.infoWindowAnchor=new GPoint(5, 1);

var iconYellow=new GIcon();
iconYellow.image='http://labs.google.com/ridefinder/images/mm_20_yellow.png';
iconYellow.shadow='http://labs.google.com/ridefinder/images/mm_20_shadow.png';
iconYellow.iconSize=new GSize(12, 20);
iconYellow.shadowSize=new GSize(22, 20);
iconYellow.iconAnchor=new GPoint(6, 20);
iconYellow.infoWindowAnchor=new GPoint(5, 1);

var customIcons = [];
customIcons["SH"]=iconBlue;
customIcons["SF"]=iconRed;
customIcons["SB"]=iconYellow;

customIcons["FH"]=iconBlue;
customIcons["FF"]=iconRed;
customIcons["FB"]=iconYellow;

customIcons["JH"]=iconBlue;
customIcons["JF"]=iconRed;
customIcons["JB"]=iconYellow;

customIcons["OH"]=iconBlue;
customIcons["OF"]=iconRed;
customIcons["OB"]=iconYellow;


function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();
map = new GMap2(document.getElementById('map'));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
//map.setCenter(new GLatLng(40, -100), 4);
map.setCenter(new GLatLng(56.26392, 9.501785), 6);
}
}

function searchLocations() {
var address = document.getElementById('addressInput').value;
geocoder.getLatLng(address, function(latlng) {
if (!latlng) {
alert(address + ' not found');
} else {
searchLocationsNear(latlng);
}
});
}

function searchLocationsNear(center) {
var radius = document.getElementById('radiusSelect').value;
var searchUrl = 'library_phpsqlsearch_genxml.php?lat=' + center.lat() +
'&lng=' + center.lng() + '&radius=' + radius; alert(searchUrl)
GDownloadUrl(searchUrl, function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName('marker') ;
map.clearOverlays();

var sidebar = document.getElementById('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = 'No results found.';
//map.setCenter(new GLatLng(40, -100), 4);
map.setCenter(new GLatLng(56.26392, 9.501785), 6);

return;
}

var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute('name');
var address = markers[i].getAttribute('address');
var icon_type = markers[i].getAttribute('icon_type');
var distance = parseFloat(markers[i].getAttribute('distance'));
var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
parseFloat(markers[i].getAttribute('lng')));

var marker = createMarker(point, name, address, icon_type);
//var marker = createMarker(point, name, address);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, name, address,
distance);
sidebar.appendChild(sidebarEntry);
bounds.extend(point);
}
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
});
}

function createMarker(point, name, address, icon_type) {
var marker = new GMarker(point, customIcons[icon_type]);
GLog.write(icon_type);
//function createMarker(point, name, address) {
//var marker = new GMarker(point);
//GLog.write(icon_type);
//var marker = new GMarker(point, {icon:customIcons[type]});


var html = '<b>' + name + '</b> <br/>' + address;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}

function createSidebarEntry(marker, name, address, distance) {
var div = document.createElement('div');
var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' +
address;
div.innerHTML = html;
div.style.cursor = 'pointer';
div.style.marginBottom = '5px';
GEvent.addDomListener(div, 'click', function() {
GEvent.trigger(marker, 'click');
});
GEvent.addDomListener(div, 'mouseover', function() {
div.style.backgroundColor = '#eee';
});
GEvent.addDomListener(div, 'mouseout', function() {
div.style.backgroundColor = '#fff';
});
return div;
}
//]]>
</script>
</head>

<body onload="load()" onunload="GUnload()">
Address: <input type="text" id="addressInput"/>

Radius: <select id="radiusSelect">
<option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="25">25</option>
<option value="100">100</option>

<option value="200">200</option>
</select>
<input type="button" onclick="searchLocations()" value="Search
Locations"/>
<br/>
<br/>
<div style="width:600px; font-family:Arial,
sans-serif; font-size:11px; border:1px solid black">
<table>
<tbody>
<tr id="cm_mapTR">
<td width="200" valign="top"> <div id="sidebar" style="overflow:
auto; height: 400px; font-size: 11px; color: #000"></div>

</td>
<!-- <td> <div id="map" style="overflow: hidden; width:400px;
height:400px"></div> </td> -->
<td> <div id="map" style="border: 1px solid black; overflow: hidden;
width:400px; height:400px"></div> </td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

/Tine



 
Reply With Quote
 
Tine Mller
Guest
Posts: n/a
 
      04-05-2008
It should have been:

library_phpsqlsearch_genxml.php

"<?php
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers_library");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers_library table
$query = sprintf("SELECT address, name, lat, lng, icon_type, ( 6371 *
acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) -
radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS
distance FROM markers_library HAVING distance < '%s' ORDER BY distance LIMIT
0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);

if (!$result) {
die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
$newnode->setAttribute("icon_type", $row['icon_type']);
}

echo $dom->saveXML();
?>


 
Reply With Quote
 
Tine Mller
Guest
Posts: n/a
 
      04-06-2008
I have made some improvements. Now all the markers can be find. The only
problem now is making instead of an ?.

I changed:
// Start XML file, create parent node
//$dom = new DOMDocument("1.0");
$dom = new DOMDocument('1.0', 'utf-8');

OS: Debian Linux 4.0 php 5.2

/Tine

 
Reply With Quote
 
Tine Mller
Guest
Posts: n/a
 
      04-06-2008
"Tine Mller" wrote
>I have made some improvements. Now all the markers can be find. The only
>problem now is making instead of an ?.
>
> I changed:
> // Start XML file, create parent node
> //$dom = new DOMDocument("1.0");
> $dom = new DOMDocument('1.0', 'utf-8');
>
> OS: Debian Linux 4.0 php 5.2


In Explorer 6 NOTHING is functioning. One minutes from going crazy.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM
Printing problems using Firefox 1.07 Danish rack Firefox 8 11-27-2005 04:15 AM



Advertisments