Darla Posted February 16, 2007 Share Posted February 16, 2007 Hello I have a database table where I have some values containing the norwegian special letters æ, ø or å. Upon fetching them it seems Ø turns into a simple "?": $sql = "SELECT description, count(description) AS count FROM userdata WHERE datetime like '".$datetime."%' GROUP BY description ORDER BY count DESC LIMIT 1"; $result = mysql_query($sql); $descres= mysql_fetch_array($result); echo "description:" . $descres['description'] ; Here is an example of output - the value should have been "SØ" like it is in the database: "description:S�" Great if someone have some idea why. Darla Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/ Share on other sites More sharing options...
Clinger Posted February 16, 2007 Share Posted February 16, 2007 Try viewing the source to ensure that it is a questionmark. Sometimes HTML will draw questionmarks. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186638 Share on other sites More sharing options...
Guest Posted February 16, 2007 Share Posted February 16, 2007 Ah, dbs (like mysql) and their tables have a collation set to them, basically it's what the kind of characters it can accept. If you've got access to PHPMyAdmin to your database, you can use that to set the collation to something like latin1_swedish_ci or something of the like. If you don't, you can run something like this SQL against your db ALTER TABLE yourtable DEFAULT COLLATE latin1; At least, that should be it. I'm not 100% sure latin1 is the right collation. Either that or something else characterset related. Probably in the HTML's metatag? <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186642 Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 See if this helps, and make sure your meta tag specifies utf-8. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186644 Share on other sites More sharing options...
Darla Posted February 16, 2007 Author Share Posted February 16, 2007 Hello Thanks for tips, but it seems id did not help. Regarding the ALTER TABLE yourtable DEFAULT COLLATE latin1; - do you think this will help? It is stored correct in the database you see, with SØ. It is when I fetch it in php it turns out wrong. Could there be something with mysql_fetch_array($result); or something? I have tried utf-8 decoding it but it seems it is not utf-8 code. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186650 Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 What character set is your table? You can find this by running SHOW CREATE TABLE table. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186654 Share on other sites More sharing options...
Darla Posted February 16, 2007 Author Share Posted February 16, 2007 When I run this query in phpmyadmin I get :TYPE=MyISAM, does this indicate the charset? I get no additional info except for field names etc. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186668 Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 After that I get a DEFAULT CHARSET=.... What version of MySQL are you running? What about phpmyadmin? Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186670 Share on other sites More sharing options...
Darla Posted February 16, 2007 Author Share Posted February 16, 2007 I use a server where I only have access to phpmyadmin, when I run the query there (in phpmyadmin) I get no DEFAULT CHARSET in the response :| Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186679 Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 How about SELECT @@version? Surely phpmyadmin should show you its version, and I would think MySQL's, somewhere on the page. Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186680 Share on other sites More sharing options...
Darla Posted February 16, 2007 Author Share Posted February 16, 2007 Here is the response for SELECT @@version: 4.0.24_Debian-10sarge2-log Quote Link to comment https://forums.phpfreaks.com/topic/38819-problem-with-special-chars-extracting-from-database-in-php/#findComment-186692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.