PHP读取数据库中文显示问号

obe007 2015-04-08 07:22:24
页面编码改成UTF-8了 数据库里的表编码改了 字段编码也改了 就是不知道为什么还是显示???问号



<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>综合素质</title>
<link rel="stylesheet" type="text/css" href="index.css">
<script src="jquery-2.1.3.js"></script>
<script src="index.js"></script>
</head>

<?PHP
$con = mysql_connect("localhost","root","");
mysql_select_db("radom100",$con);
session_start();
$sql = "select * from user2";
$result = mysql_query($sql);
$arr = array();
while($row = mysql_fetch_array($result)){
$arr[] = $row;
}

$txt = '';

foreach($arr as $key){
$txt = '<tr>
<td width="4%" style=" text-align:center;">'.$key['id'].'</td>
<td width="77%">'.$key['choice'].'</td>
<td width="19%">'.$key['select'].'</td>
</tr>';
}



?>

<body>
<table width="80%" align="center" border="1px" cellpadding="10" cellspacing="2">
<tr>
<th style="font-family: 楷体; font-size: 20px;">编号</th>
<th style="font-family:楷体; font-size: 40px;">题目</th>
<th width="19%" style="font-family:楷体; font-size:28px;">答案</th>
</tr>
<?PHP echo $txt; ?>
<tr>
<td width="4%"> </td>
<td width="77%"> </td>
<td width="19%"> </td>
</tr>
</table>




</body>
</html>
...全文
1547 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChanKalam 2015-04-09
  • 打赏
  • 举报
回复
mysql_query('set names utf8');
xuzuning 2015-04-09
  • 打赏
  • 举报
回复
连接数据库后,要执行一句 mysql_query(set names XXX'); XXX 是你所需字符集的代号 utf8 或 gbk
wenfei307 2015-04-09
  • 打赏
  • 举报
回复
解决方法不说了,前面大家都给出来了mysql_query(set names utf8'); 以后的话这种问题一看就是编码问题,遇到这样的问题先检查数据库的编码和前台的编码,常见的情况就是你的这种情况,或者导入或者导出的时候编码就是错的,或者前台没有设定编码。这三种情况是最常见的。
zhangsheng_1992 2015-04-09
  • 打赏
  • 举报
回复
mysql_query(set names utf8');是必须的 数据库里的字段是你手动写进去的吧 asii与utf8的字节长度不一样 转换编码以后utf8字节对不上 所以会出现问号 建议你把那个删除了从新插入吧
傲雪星枫 2015-04-09
  • 打赏
  • 举报
回复
查詢前,先 mysql_query('set names utf8'); 參考:http://blog.csdn.net/fdipzone/article/details/18180325

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧