-2

I have a data in my mysql database's table which is Biñan. However, when I try to retrieve it using php, it showed as Bi�an in my dropdown list.

Here is my sample code:

<?php
   $query = "SELECT * from municipality";
   $res = mysqli_query($conn,$query);
   while($row = mysqli_fetch_assoc($res))
   {
     echo "<option value='".$row['m_id']."'>".$row['m_name']."</option>";
   }
?>

But when I manually echo/insert the character ñ in php/mysql it displayed as is. I have also set the charset to UTF-8.

PROBLEM SOLVED!: I just have to replace the ñ with ñ in my database's table. So it shows ñ in my website.

ravendee
  • 1
  • 3
  • **NO!** Two wrongs do not make a right! Don't "replace the `ñ` with `ñ`"! See "black diamond" in https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored for the likely cause(s) of such. That should help you solve it completely, not one case at a time! – Rick James Aug 20 '18 at 04:13

3 Answers3

0

add this in your head html file.

in a balise:

meta http-equiv="Content-Type" content="text/html; charset=UTF-8"

Berthol Yvano
  • 306
  • 3
  • 8
0

Try to:

ALTER DATABASE <databasename> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE municipality CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
zen
  • 980
  • 6
  • 18
0

otherwise it's in the database. do this in your database.

ALTER TABLE municipality COLLATE utf8_general_ci

or

ALTER TABLE municipality CONVERT TO CHARACTER SET utf8;

Berthol Yvano
  • 306
  • 3
  • 8