查询两个字段就乱码
本帖最后由 永恒forever 于 2012-9-18 17:02 编辑我有一个表 news,表结构如下:
CREATE TABLE `news` (`news_id` INT(11) NOT NULL AUTO_INCREMENT,`news_title` VARCHAR(100) NOT NULL,`news_content` TEXT NOT NULL,`news_category_id` INT(11) NOT NULL,`news_user_id` INT(11) NOT NULL,`news_created_time` INT(10) NOT NULL,PRIMARY KEY (`news_id`))COLLATE='utf8_general_ci'ENGINE=InnoDBAUTO_INCREMENT=2;
Model 代码为:
public function getNews($id = FALSE) { if ($id === FALSE) {
$this->db->select('news_title,news_content,news_created_time');
$query = $this->db->get('news');
return $query->result_array();
}
// $this->db->select('news_title'); //只选这个字段,页面正常
// $this->db->select('news_content'); //只选这个字段,页面也正常
$this->db->select('news_content,news_title'); //但是这两个字段都选,就出现乱码,并且刷新几次,可能有一次会正常
$query = $this->db->get_where('news', array('news_id' => $id));
return $query->row_array();
}
控制器相关代码为:
public function test($id) { $query = $this->news_model->getNews($id);
var_dump($query);
}
我一直用的是 chrome ,
刚才我用 IE 和 Firefox 访问就没有出现乱码了。 没有问题了。我知道原因了,因为我输出的时候没有并设置页面编码。
在 view 里有 <meta charset="utf-8">后就不会乱码了。
谢谢大家。 我自认 PHP 基础知识很扎实,也有 C/C++ 语言基础。
但是总感觉要自己写个东西出来还是很困难,该如何提高呢。 希望与大家多多交流。
页:
[1]